diff options
author | Alan Pearce | 2023-09-12 18:41:59 +0200 |
---|---|---|
committer | Alan Pearce | 2023-09-12 18:41:59 +0200 |
commit | b89c78af528b400d31ce59576fc4238b902a9cfe (patch) | |
tree | 5ba41111e38120a9e82bc2082cb02499a8bfea09 /src | |
parent | d4c067d0baff81a308c01ea62a900075b0326b7d (diff) | |
download | website-b89c78af528b400d31ce59576fc4238b902a9cfe.tar.lz website-b89c78af528b400d31ce59576fc4238b902a9cfe.tar.zst website-b89c78af528b400d31ce59576fc4238b902a9cfe.zip |
Send status code 404 with /404.html
Diffstat (limited to 'src')
-rw-r--r-- | src/index.ts | 9 |
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); } } |