This commit is contained in:
2026-02-04 15:13:15 +00:00
parent 39c31b17c3
commit 9976362840
5 changed files with 98 additions and 18 deletions

39
src/server.ts Normal file
View File

@@ -0,0 +1,39 @@
import { readdir } from "node:fs/promises";
import { join } from "node:path";
import { Hono } from "hono";
import { serveStatic } from "hono/bun";
const app = new Hono();
app.use("/fonts/*", serveStatic({ root: "." }));
app.use("/*", serveStatic({ root: "./public" }));
const cssDir = "css";
const cssRoutes = async () => {
const entries = await readdir(cssDir, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isFile() || !entry.name.endsWith(".css")) {
continue;
}
const route = `/${entry.name.replace(".css", "")}`;
const filePath = join(cssDir, entry.name);
app.get(route, async (c) => {
const css = await Bun.file(filePath).text();
return c.text(css, 200, {
"Content-Type": "text/css; charset=utf-8",
});
});
}
};
await cssRoutes();
const port = Number(Bun.env.PORT ?? 3000);
export default {
fetch: app.fetch,
port,
};