feat: initialize VitePress CMS

This commit is contained in:
Coldsmile_7
2026-06-05 23:21:41 +08:00
commit 928f742d5e
45 changed files with 8214 additions and 0 deletions

45
server.mjs Normal file
View File

@@ -0,0 +1,45 @@
import { createReadStream, existsSync } from "node:fs";
import { extname, join, normalize } from "node:path";
import { createServer } from "node:http";
const port = Number(process.env.PORT || 5173);
const root = process.cwd();
const mimeTypes = {
".html": "text/html; charset=utf-8",
".js": "text/javascript; charset=utf-8",
".css": "text/css; charset=utf-8",
".json": "application/json; charset=utf-8",
".svg": "image/svg+xml",
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
};
function resolveRequest(url) {
const pathname = decodeURIComponent(new URL(url, `http://localhost:${port}`).pathname);
const requestedPath = normalize(join(root, pathname === "/" ? "index.html" : pathname));
if (!requestedPath.startsWith(root)) {
return null;
}
return requestedPath;
}
createServer((request, response) => {
const filePath = resolveRequest(request.url || "/");
if (!filePath || !existsSync(filePath)) {
response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
response.end("Not found");
return;
}
response.writeHead(200, {
"Content-Type": mimeTypes[extname(filePath)] || "application/octet-stream",
});
createReadStream(filePath).pipe(response);
}).listen(port, () => {
console.log(`VitePress-CMS prototype running at http://localhost:${port}`);
});