aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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",
+ },
+ });
});
}