This commit is contained in:
hero920103 committed 2026-10-19 01:13:17 +08:00
1 parent 5718a00e31
commit 1850ac640e
226 files changed
+37772 -12071

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { createServer } from "node:http";
import { readFile } from "node:fs/promises";
import { extname, join } from "node:path";
const root = join(import.meta.dirname, "dist");
const port = Number(process.argv[2] || 4173);
const types = {
".html": "text/html; charset=utf-8",
".css": "text/css; charset=utf-8",
".js": "text/javascript; charset=utf-8",
".svg": "image/svg+xml",
};
createServer(async (req, res) => {
const path = new URL(req.url, "http://127.0.0.1").pathname;
const file = path === "/" ? "index.html" : path;
try {
const body = await readFile(join(root, file));
res.writeHead(200, { "content-type": types[extname(file)] || "application/octet-stream" });
res.end(body);
} catch {
res.writeHead(404).end("not found");
}
}).listen(port, "127.0.0.1", () => console.log(`preview http://127.0.0.1:${port}/`));