aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-18 19:05:33 +0900
committernsfisis <nsfisis@gmail.com>2023-03-18 19:05:33 +0900
commit4b1b65fb57b59c01a8c5480db44f177e7d6d9752 (patch)
tree6ac6a3320dd9e481ee217793e1879b045c57859e /nuldoc-src
parent71aba3df235dc9a8acbee0e33980b30ba4ce44d4 (diff)
downloadblog.nsfisis.dev-4b1b65fb57b59c01a8c5480db44f177e7d6d9752.tar.gz
blog.nsfisis.dev-4b1b65fb57b59c01a8c5480db44f177e7d6d9752.tar.zst
blog.nsfisis.dev-4b1b65fb57b59c01a8c5480db44f177e7d6d9752.zip
feat(nuldoc): support custom 404 in serve command
Diffstat (limited to 'nuldoc-src')
-rw-r--r--nuldoc-src/commands/serve.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/nuldoc-src/commands/serve.ts b/nuldoc-src/commands/serve.ts
index b66ad2d..ffb2020 100644
--- a/nuldoc-src/commands/serve.ts
+++ b/nuldoc-src/commands/serve.ts
@@ -1,6 +1,7 @@
-import { join } from "std/path/mod.ts";
import { serveDir } from "std/http/file_server.ts";
+import { Status, STATUS_TEXT } from "std/http/http_status.ts";
import { serve } from "std/http/server.ts";
+import { join } from "std/path/mod.ts";
import { Config } from "../config.ts";
export function runServeCommand(config: Config) {
@@ -14,9 +15,21 @@ export function runServeCommand(config: Config) {
await p.status();
console.log("rebuild");
}
- return serveDir(req, {
+ const res = await serveDir(req, {
fsRoot: rootDir,
showIndex: true,
});
+ if (res.status !== Status.NotFound) {
+ return res;
+ }
+
+ const notFoundHtml = await Deno.readTextFile(join(rootDir, "404.html"));
+ return new Response(notFoundHtml, {
+ status: Status.NotFound,
+ statusText: STATUS_TEXT[Status.NotFound],
+ headers: {
+ "content-type": "text/html",
+ },
+ });
});
}