Skip to content

Commit

Permalink
Check for attempts to prefetch the data, and ignore them
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Feb 18, 2024
1 parent ca4783e commit 57394bf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,18 @@ router.get('/:projectSlug/source/:sourceId', async (ctx) =>
);
router.get('/:projectSlug/timeline', async (ctx) => renderTimeline(ctx, db));
router.get('/:projectSlug/data', async (ctx) => renderProjectDataPage(ctx, db));
router.get('/:projectSlug/data/:expId', async (ctx) =>
renderDataExport(ctx, db)
);
router.get('/:projectSlug/data/:expId', async (ctx) => {
if (
ctx.header['X-Purpose'] === 'preview' ||
ctx.header['Purpose'] === 'prefetch' ||
ctx.header['X-Moz'] === 'prefetch'
) {
ctx.set('Cache-Control', 'must-revalidate');
ctx.status = 425; // HTTP Code for 'Too Early'
return;
}
return renderDataExport(ctx, db);
});
router.get('/:projectSlug/compare/:baseline..:change', async (ctx) =>
renderComparePage(ctx, db)
);
Expand Down

0 comments on commit 57394bf

Please sign in to comment.