fix: 🔒 Show 404 error on files not found

This commit is contained in:
ThatOneCalculator 2023-07-27 01:28:02 -07:00
parent 65bbf8541a
commit dacce643fe
No known key found for this signature in database
GPG key ID: 8703CACD01000000

View file

@ -114,24 +114,48 @@ const router = new Router();
//#region static assets //#region static assets
router.get("/static-assets/(.*)", async (ctx) => { router.get("/static-assets/(.*)", async (ctx) => {
try {
await send(ctx as any, ctx.path.replace("/static-assets/", ""), { await send(ctx as any, ctx.path.replace("/static-assets/", ""), {
root: staticAssets, root: staticAssets,
maxage: 7 * DAY, maxage: 7 * DAY,
}); });
} catch (e) {
if (e.status === 404) {
ctx.throw(404, "File not found");
} else {
throw e;
}
}
}); });
router.get("/client-assets/(.*)", async (ctx) => { router.get("/client-assets/(.*)", async (ctx) => {
try {
await send(ctx as any, ctx.path.replace("/client-assets/", ""), { await send(ctx as any, ctx.path.replace("/client-assets/", ""), {
root: clientAssets, root: clientAssets,
maxage: 7 * DAY, maxage: 7 * DAY,
}); });
} catch (e) {
if (e.status === 404) {
ctx.throw(404, "File not found");
} else {
throw e;
}
}
}); });
router.get("/assets/(.*)", async (ctx) => { router.get("/assets/(.*)", async (ctx) => {
try {
await send(ctx as any, ctx.path.replace("/assets/", ""), { await send(ctx as any, ctx.path.replace("/assets/", ""), {
root: assets, root: assets,
maxage: 7 * DAY, maxage: 7 * DAY,
}); });
} catch (e) {
if (e.status === 404) {
ctx.throw(404, "File not found");
} else {
throw e;
}
}
}); });
// Apple touch icon // Apple touch icon