about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2023-09-12 18:41:59 +0200
committerAlan Pearce2023-09-12 18:41:59 +0200
commitb89c78af528b400d31ce59576fc4238b902a9cfe (patch)
tree5ba41111e38120a9e82bc2082cb02499a8bfea09
parentd4c067d0baff81a308c01ea62a900075b0326b7d (diff)
downloadwebsite-b89c78af528b400d31ce59576fc4238b902a9cfe.tar.lz
website-b89c78af528b400d31ce59576fc4238b902a9cfe.tar.zst
website-b89c78af528b400d31ce59576fc4238b902a9cfe.zip
Send status code 404 with /404.html
-rw-r--r--src/index.ts9
1 files changed, 6 insertions, 3 deletions
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<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);
   }
 }