openvibers/openvibe.finance Commits

SEO: the signed-out welcome may be indexed (#31)

OP OpenVibers committed 8 days ago · a56c2f5db1 · 2 files, +16 −2

The 11-23 network crawl: openvibe.finance's home was in its sitemap but every response carried
X-Robots-Tag: noindex, nofollow, which outweighs the page's own index, follow (the 11-21 pass
opened robots.txt and the meta tag but left the header). The header now goes on everything except
a signed-out GET of the welcome and the crawl files; a signed-in page (someone's money) always
gets it. Test: app (signed out, signed in, another page).

Changes

ddiff --git a/server/app.js b/server/app.js
iindex 6fa646e..2bb5707 100644
---- a/server/app.js
++++ b/server/app.js
@@@ -37,8 +37,13 @@ function createApp({ db, vault, auth, mcpAuth = null, baseUrl = 'https://openvib
require('openvibe-shared/metrics').instrument(app, { service: 'finance', release: release.release });
app.get('/release.json', release.handler);
} catch { /* metrics are optional in tests */ }
++ // Out of the index: everything but the public welcome (GET /) and the crawl files. This header used to go on every
++ // response, the welcome too, and it outweighs the page's own "index, follow": the 11-23 crawl found the home
++ // noindex while its sitemap listed it. A signed-in person's pages (their money) get it again below.
++ const INDEXABLE = new Set(['/', '/robots.txt', '/sitemap.xml', '/llms.txt']);
app.use((req, res, next) => {
-- res.set({ 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'same-origin', 'X-Frame-Options': 'DENY', 'X-Robots-Tag': 'noindex, nofollow' });
++ res.set({ 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'same-origin', 'X-Frame-Options': 'DENY' });
++ if (!((req.method === 'GET' || req.method === 'HEAD') && INDEXABLE.has(req.path))) res.set('X-Robots-Tag', 'noindex, nofollow');
next();
});
app.get('/api/health', (_req, res) => res.json({ status: 'ok', service: 'finance' }));
@@@ -69,7 +74,11 @@ function createApp({ db, vault, auth, mcpAuth = null, baseUrl = 'https://openvib
(req, res, next) => { res.set('Cache-Control', 'private, no-store'); Promise.resolve(finMcp.handler(req, res)).catch(next); });
app.all('/mcp', (_req, res) => res.status(405).set('Allow', 'POST').json({ error: 'POST a JSON-RPC request.' }));
app.use(auth ? auth.optionalAuth() : (_req, _res, next) => next());
-- app.use((req, res, next) => { res.set('Cache-Control', 'private, no-store'); next(); });
++ app.use((req, res, next) => {
++ res.set('Cache-Control', 'private, no-store');
++ if (req.user) res.set('X-Robots-Tag', 'noindex, nofollow'); // a signed-in page shows someone's money
++ next();
++ });
// The pages and the API: the person's own sign-in only. A delegated token (something acting for them) is for /mcp.
const { isDelegated } = require('openvibe-sdk/auth/delegated');
ddiff --git a/test/app.test.js b/test/app.test.js
iindex edccdca..3a12887 100644
---- a/test/app.test.js
++++ b/test/app.test.js
@@@ -48,7 +48,12 @@ const SAME = { 'sec-fetch-site': 'same-origin' };
assert.match(home.text, /No money moves/);
assert.match(home.text, /href="\/finance\.css\?v=[0-9a-f]{10}"><script src="\/finance\.js\?v=[0-9a-f]{10}" defer>/, 'our files by their content');
assert.strictEqual(home.headers.get('cache-control'), 'private, no-store');
++ // The welcome is for search engines (the 11-23 crawl: a noindex header on it outweighed its "index, follow").
++ assert.strictEqual(home.headers.get('x-robots-tag'), null, 'the signed-out welcome may be indexed');
++ assert.match(home.text, /<meta name="robots" content="index, follow">/);
++ assert.strictEqual((await go('/', { as: ADA })).headers.get('x-robots-tag'), 'noindex, nofollow', 'a signed-in home (someone\'s money) never');
const month = await go('/month');
++ assert.strictEqual(month.headers.get('x-robots-tag'), 'noindex, nofollow', 'nor any other page');
assert.strictEqual(month.status, 303);
assert.match(month.location, /^\/auth\/login\?next=/);
assert.strictEqual((await go('/api/v1/accounts')).status, 401);