Send status code 404 with /404.html
Alan Pearce alan@alanpearce.eu
Tue, 12 Sep 2023 18:41:59 +0200
1 files changed, 6 insertions(+), 3 deletions(-)
jump to
M src/index.ts → src/index.ts
@@ -66,14 +66,17 @@ } walkDirectory(publicDir, ""); -async function serveFile(file: File | undefined): Promise<Response> { +async function serveFile( + file: File | undefined, + statusCode: number = 200, +): Promise<Response> { if (file && (await fsp.exists(file.filename))) { return new Response(Bun.file(file.filename), { headers: file.headers, - status: 200, + status: statusCode, }); } else { - return serveFile(files.get("/404.html")); + return serveFile(files.get("/404.html"), 404); } }