openvibers/openvibe.mediahub Commits

Video host: an unknown /api path is a JSON 404 problem, not the HTML not-found page (#92)

OP OpenVibers committed 27 days ago · c11d36258d · 2 files, +8 −0

Changes

ddiff --git a/server/video/pages.js b/server/video/pages.js
iindex 8091569..c1ad00a 100644
---- a/server/video/pages.js
++++ b/server/video/pages.js
@@@ -1241,6 +1241,8 @@ ${isOwner ? html`<p class="ovv-fine">You can reorder items with the up and down
r.get(legal.PATHS, legal.handler({ id: 'media-hub', service: 'media-hub', host: videoHostname, name: 'OpenVibe.Video', profile: 'ugc' }));
// ── Video host 404 and errors ───────────────────────────
++ // An unknown /api path is a JSON problem like on every other OpenVibe host (it was this page's HTML 404).
++ r.use('/api', (req, res) => require('openvibe-contracts').http.sendProblem(res, 404, 'route.not_found', { detail: 'No such API route', ctx: req.ov }));
r.use((req, res) => notFound(req, res));
// eslint-disable-next-line no-unused-vars
ddiff --git a/test/video-pages.test.js b/test/video-pages.test.js
iindex 9dd06c7..cfa03d4 100644
---- a/test/video-pages.test.js
++++ b/test/video-pages.test.js
@@@ -320,6 +320,12 @@ function countOccurrences(haystack, needle) {
assert.match(r.text, /<img src="[^"]*\/avatar\/streamer" alt="" loading="lazy">/, 'the person\'s picture over the letter');
});
++ await check('an unknown /api path on the video host is a JSON 404, not a page', async () => {
++ const r = await getVideo('/api/nope');
++ assert.strictEqual(r.status, 404);
++ assert.match(String(r.headers['content-type']), /json/);
++ });
++
await check('a name nobody has, with nothing to show, is a 404 (not an empty channel page)', async () => {
const r = await getVideo('/@nobody_here_x9');
assert.strictEqual(r.status, 404);