openvibers/openvibe.mediahub Commits
Video host: an unknown /api path is a JSON 404 problem, not the HTML not-found page (#92)
Changes
@@@ -1241,6 +1241,8 @@ ${isOwner ? html`<p class="ovv-fine">You can reorder items with the up and downr.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@@@ -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);
@@ -1241,6 +1241,8 @@ ${isOwner ? html`<p class="ovv-fine">You can reorder items with the up and down
@@ -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' }));
r.get(legal.PATHS, legal.handler({ id: 'media-hub', service: 'media-hub', host: videoHostname, name: 'OpenVibe.Video', profile: 'ugc' }));
// ── Video host 404 and errors ───────────────────────────
// ── 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));
r.use((req, res) => notFound(req, res));
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-unused-vars
@@ -320,6 +320,12 @@ function countOccurrences(haystack, needle) {
@@ -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');
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 () => {
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');
const r = await getVideo('/@nobody_here_x9');
assert.strictEqual(r.status, 404);
assert.strictEqual(r.status, 404);