all repos — website @ b89c78af528b400d31ce59576fc4238b902a9cfe

My website

Send status code 404 with /404.html
Alan Pearce alan@alanpearce.eu
Tue, 12 Sep 2023 18:41:59 +0200
commit

b89c78af528b400d31ce59576fc4238b902a9cfe

parent

d4c067d0baff81a308c01ea62a900075b0326b7d

1 files changed, 6 insertions(+), 3 deletions(-)

jump to
M src/index.tssrc/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);
   }
 }