Separate runtime manifest inputs from directly served files

This commit is contained in:
Jonathan Sykes
2026-10-09 14:40:46 +08:00
parent 0b8e398469
commit dd09f66578
5 changed files with 88 additions and 14 deletions

View File

@@ -2498,12 +2498,12 @@ app.get('/index.html', indexHtml);
// current body with no-store, never immutable caching under a mismatched URL.
app.get('/*', async (c, next) => {
const p = decodeURIComponent(new URL(c.req.url).pathname);
if (p.includes('..') || p.startsWith('/api/') || !assets.manifest.files[p]) return next();
if (p.includes('..') || p.startsWith('/api/') || !assets.deliveryFiles[p]) return next();
const file = Bun.file('./public' + p);
const raw = assets.bytes.get(p);
const ext = p.slice(p.lastIndexOf('.') + 1).toLowerCase();
const hash = assets.manifest.files[p].h;
const cacheControl = assetCacheControl(p, c.req.query('v'), assets.manifest, ASSET_HASHING);
const hash = assets.deliveryFiles[p].h;
const cacheControl = assetCacheControl(p, c.req.query('v'), assets.manifest, ASSET_HASHING, assets.deliveryFiles);
if (COMPRESSIBLE.test(p)) return sendCompressed(c, compressedEntry(p, raw, MIME[ext] || file.type), cacheControl, hash);
return new Response(raw, { headers: { 'Content-Type': file.type, 'Cache-Control': cacheControl, 'X-Asset-Hash': hash } });
});