Skip to content

Commit

Permalink
Serve missing internal files as 404 instead of soft-404 page
Browse files Browse the repository at this point in the history
## Issue
Requesting for an invalid js file like `https://odysee.com/public/some-non-existent-file.js` yields HTML, which is usually incorrectly redirect to an actual claim, or a soft-404 page.

It's not only showing incorrectly data, but it is being cached. This is one of the potential causes for the problem of users being stuck with bad cache.

## Approach
- In the final catch-all stage, try to detect if it's a file request, and return a 404 instead.
- Do no cache 404s. Same as https://community.cloudflare.com/t/404s-and-caching/337151. The file could eventually be corrected, but users remain stuck with 404.

## Concerns
- Is the detection too loose?
  • Loading branch information
infinite-persistence committed Oct 4, 2023
1 parent 9d8426a commit b9905bf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions web/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ router.get(`/$/rss/:claimName::claimId`, rssMiddleware);
router.get(`/$/oembed`, oEmbedMiddleware);

router.get('*', async (ctx) => {
const requestedUrl = ctx.url;

if (requestedUrl.startsWith('/public/') && requestedUrl.endsWith('.js')) {
// If the file exists, `app.use(serve(DIST_ROOT))` would have handled it.
// Handle the non-existent file here, otherwise it'll get resolved to a
// claim with the name 'public'.
ctx.status = 404;
ctx.body = 'Resource not found';
ctx.set('Cache-Control', 'no-store');
return;
}

const html = await getHtml(ctx);
ctx.body = html;
});
Expand Down

0 comments on commit b9905bf

Please sign in to comment.