Prepare static site for deployment
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
commit
59ad2d013e
15 files changed
+526
No files matched your search
@@ -0,0 +1,22 @@
|
||||
const root = `${import.meta.dir}/../dist`;
|
||||
const contentTypes = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".svg": "image/svg+xml"
|
||||
};
|
||||
|
||||
Bun.serve({
|
||||
port: Number(process.env.PORT || 4173),
|
||||
async fetch(request) {
|
||||
const url = new URL(request.url);
|
||||
const relative = url.pathname === "/" ? "/index.html" : url.pathname;
|
||||
if (relative.includes("..")) return new Response("Not found", { status: 404 });
|
||||
const file = Bun.file(`${root}${relative}`);
|
||||
if (!(await file.exists())) return new Response("Not found", { status: 404 });
|
||||
const extension = relative.slice(relative.lastIndexOf("."));
|
||||
return new Response(file, { headers: { "content-type": contentTypes[extension] || "application/octet-stream" } });
|
||||
}
|
||||
});
|
||||
|
||||
console.log("如饮AI preview: http://127.0.0.1:4173");
|
||||
Reference in new issue
Block a user