diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-09-07 22:27:48 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-09-07 22:35:53 +0900 |
| commit | 994e0114d76ae19768d5c303874a968cf6369fd0 (patch) | |
| tree | 5fd3f8b169eea00084b24fbae820f75273864d2a /vhosts/blog/nuldoc-src/commands/serve.ts | |
| parent | 57f015992f678bfd7281f171fb9d71349c96a1a0 (diff) | |
| download | nsfisis.dev-994e0114d76ae19768d5c303874a968cf6369fd0.tar.gz nsfisis.dev-994e0114d76ae19768d5c303874a968cf6369fd0.tar.zst nsfisis.dev-994e0114d76ae19768d5c303874a968cf6369fd0.zip | |
meta: migrate to monorepo
Diffstat (limited to 'vhosts/blog/nuldoc-src/commands/serve.ts')
| -rw-r--r-- | vhosts/blog/nuldoc-src/commands/serve.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vhosts/blog/nuldoc-src/commands/serve.ts b/vhosts/blog/nuldoc-src/commands/serve.ts new file mode 100644 index 00000000..aa5221df --- /dev/null +++ b/vhosts/blog/nuldoc-src/commands/serve.ts @@ -0,0 +1,38 @@ +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) { + const rootDir = join(Deno.cwd(), config.locations.destDir); + serve(async (req) => { + const pathname = new URL(req.url).pathname; + if (!pathname.endsWith("css") && !pathname.endsWith("svg")) { + const command = new Deno.Command( + join(Deno.cwd(), "nuldoc"), + { + args: ["build"], + }, + ); + await command.output(); + console.log("rebuild"); + } + 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", + }, + }); + }); +} |
