diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-01 02:28:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-01 02:28:10 +0900 |
| commit | cd16ed5d6b46d91ae9ac7b2237d6405ad6715a4a (patch) | |
| tree | 0e00d7caf3031fa86decaa0cbc226cc1e521b914 /services/nuldoc/nuldoc-src/commands/serve.ts | |
| parent | d08e3edb65b215152aa26e3518fb2f2cd7071c4b (diff) | |
| parent | 1964f77d03eb647dcf46d63dde68d7ae7301604f (diff) | |
| download | nsfisis.dev-cd16ed5d6b46d91ae9ac7b2237d6405ad6715a4a.tar.gz nsfisis.dev-cd16ed5d6b46d91ae9ac7b2237d6405ad6715a4a.tar.zst nsfisis.dev-cd16ed5d6b46d91ae9ac7b2237d6405ad6715a4a.zip | |
Merge branch 'feat/ruby-rewrite'
Diffstat (limited to 'services/nuldoc/nuldoc-src/commands/serve.ts')
| -rw-r--r-- | services/nuldoc/nuldoc-src/commands/serve.ts | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/services/nuldoc/nuldoc-src/commands/serve.ts b/services/nuldoc/nuldoc-src/commands/serve.ts deleted file mode 100644 index 8388d48a..00000000 --- a/services/nuldoc/nuldoc-src/commands/serve.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { parseArgs } from "@std/cli"; -import { serveDir, STATUS_CODE, STATUS_TEXT } from "@std/http"; -import { join } from "@std/path"; -import { Config } from "../config.ts"; -import { runBuildCommand } from "./build.ts"; - -function isResourcePath(pathname: string): boolean { - const EXTENSIONS = [ - ".css", - ".gif", - ".ico", - ".jpeg", - ".jpg", - ".js", - ".mjs", - ".png", - ".svg", - ]; - return EXTENSIONS.some((ext) => pathname.endsWith(ext)); -} - -export function runServeCommand(config: Config) { - const parsedArgs = parseArgs(Deno.args, { - boolean: ["no-rebuild"], - }); - - const doRebuild = !parsedArgs["no-rebuild"]; - const siteName = String(parsedArgs._[1]); - if (siteName === "") { - throw new Error("Usage: nuldoc serve <site>"); - } - - const rootDir = join(Deno.cwd(), config.locations.destDir, siteName); - Deno.serve({ hostname: "127.0.0.1" }, async (req) => { - const pathname = new URL(req.url).pathname; - if (!isResourcePath(pathname) && doRebuild) { - await runBuildCommand(config); - console.log("rebuild"); - } - const res = await serveDir(req, { - fsRoot: rootDir, - showIndex: true, - }); - if (res.status !== STATUS_CODE.NotFound) { - return res; - } - - const notFoundHtml = await Deno.readTextFile(join(rootDir, "404.html")); - return new Response(notFoundHtml, { - status: STATUS_CODE.NotFound, - statusText: STATUS_TEXT[STATUS_CODE.NotFound], - headers: { - "content-type": "text/html", - }, - }); - }); -} |
