From b89c78af528b400d31ce59576fc4238b902a9cfe Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 12 Sep 2023 18:41:59 +0200 Subject: Send status code 404 with /404.html --- src/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 27af7a7..030b0bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,14 +66,17 @@ function walkDirectory(root: string, dir: string) { walkDirectory(publicDir, ""); -async function serveFile(file: File | undefined): Promise { +async function serveFile( + file: File | undefined, + statusCode: number = 200, +): Promise { 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); } } -- cgit 1.4.1