openvibers/openvibe.services Commits

Services: /docs/contracts/<name>@<major> opens that contract's page (#69)

OP OpenVibers committed 29 days ago · 3aeca635aa · 2 files, +14 −0

Contract pages answer to the way the platform writes a contract id. `/docs/contracts/<name>@<major>` (for example `actor.task-webhook@1`) now redirects with a 301 to `/docs/contracts/<name>` when that major is the one documented. Another major answers 404.

A site-wide crawl found openvibe.actor's docs linking `actor.task-webhook@1` and `platform.task@1` here, both 404. Any link written the platform's way now works.

`test/docs.test.js` checks the redirect and the 404 for another major.

Changes

ddiff --git a/server/http/docs.js b/server/http/docs.js
iindex a80047d..20c6639 100644
---- a/server/http/docs.js
++++ b/server/http/docs.js
@@@ -92,6 +92,14 @@ ${table(['Contract', 'Version', 'Owner', 'Visibility', 'Status', 'Compatibility'
});
r.get('/contracts/:id', (req, res, next) => {
++ // A contract named the way the platform writes it, `<name>@<major>` (actor.task-webhook@1): its page, when that
++ // major is the one documented here.
++ const versioned = /^(.+)@(\d+)$/.exec(String(req.params.id));
++ if (versioned) {
++ const named = docs.contract(versioned[1]);
++ if (named && named.version.split('.')[0] === versioned[2]) return res.redirect(301, `/docs/contracts/${encodeURIComponent(named.id)}`);
++ return next();
++ }
const c = docs.contract(req.params.id);
if (!c) return next();
const major = c.version.split('.')[0];
ddiff --git a/test/docs.test.js b/test/docs.test.js
iindex 855dc85..19d7457 100644
---- a/test/docs.test.js
++++ b/test/docs.test.js
@@@ -57,6 +57,12 @@ const sdkPkg = require('openvibe-sdk/package.json');
assert.deepStrictEqual(JSON.parse(raw.text), schema);
}
assert.strictEqual((await t.get('/docs/contracts/no.such-contract')).status, 404);
++ // The way the platform writes a contract, name@major, opens its page; another major does not.
++ const one = contracts.catalog[0];
++ const major = one.version.split('.')[0];
++ const versioned = await t.get(`/docs/contracts/${one.id}@${major}`);
++ assert.deepStrictEqual([versioned.status, versioned.headers.get('location')], [301, `/docs/contracts/${encodeURIComponent(one.id)}`]);
++ assert.strictEqual((await t.get(`/docs/contracts/${one.id}@${Number(major) + 7}`)).status, 404);
});
await check('the capability catalog lists every capability manifest exactly once', async () => {