更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -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}/`));
|
||||
Reference in new issue
Block a user