fix: 🔒 Show 404 error on files not found
This commit is contained in:
parent
65bbf8541a
commit
dacce643fe
1 changed files with 36 additions and 12 deletions
|
@ -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) => {
|
||||||
await send(ctx as any, ctx.path.replace("/static-assets/", ""), {
|
try {
|
||||||
root: staticAssets,
|
await send(ctx as any, ctx.path.replace("/static-assets/", ""), {
|
||||||
maxage: 7 * DAY,
|
root: staticAssets,
|
||||||
});
|
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) => {
|
||||||
await send(ctx as any, ctx.path.replace("/client-assets/", ""), {
|
try {
|
||||||
root: clientAssets,
|
await send(ctx as any, ctx.path.replace("/client-assets/", ""), {
|
||||||
maxage: 7 * DAY,
|
root: clientAssets,
|
||||||
});
|
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) => {
|
||||||
await send(ctx as any, ctx.path.replace("/assets/", ""), {
|
try {
|
||||||
root: assets,
|
await send(ctx as any, ctx.path.replace("/assets/", ""), {
|
||||||
maxage: 7 * DAY,
|
root: assets,
|
||||||
});
|
maxage: 7 * DAY,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e.status === 404) {
|
||||||
|
ctx.throw(404, "File not found");
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Apple touch icon
|
// Apple touch icon
|
||||||
|
|
Loading…
Reference in a new issue