diff --git a/api/index.ts b/api/index.ts deleted file mode 100644 index 50a7908..0000000 --- a/api/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { handle } from "hono/vercel"; -import { app } from "../src/server"; - -export default handle(app); diff --git a/src/server.ts b/src/server.ts index 843664b..2f156ae 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,7 +1,7 @@ -import { readFile, readdir, stat } from "node:fs/promises"; +import { readdir } from "node:fs/promises"; import { join, parse } from "node:path"; import { Hono } from "hono"; -import { serveStatic } from "hono/serve-static"; +import { serveStatic } from "hono/bun"; const app = new Hono(); @@ -10,27 +10,6 @@ const templatePath = join("public", "index.html"); const cardPlaceholder = ""; const importPlaceholder = "/* FONT_IMPORT */"; -const serveStaticFromFs = (options: { root: string }) => - serveStatic({ - root: options.root, - getContent: async (path) => { - try { - return await readFile(path); - } catch (error) { - return null; - } - }, - isDir: async (path) => { - try { - const stats = await stat(path); - return stats.isDirectory(); - } catch (error) { - return undefined; - } - }, - join, - }); - const escapeHtml = (value: string) => value .replaceAll("&", "&") @@ -79,7 +58,7 @@ const buildFontCatalog = async () => { const baseName = parse(fileName).name; const route = `/${baseName}`; const filePath = join(cssDir, fileName); - const css = await readFile(filePath, "utf8"); + const css = await Bun.file(filePath).text(); const families = parseFontFamilies(css); if (families.length === 0) { @@ -113,7 +92,7 @@ const buildFontCatalog = async () => { }; }; -const templateHtml = await readFile(templatePath, "utf8"); +const templateHtml = await Bun.file(templatePath).text(); const { cards, importCss } = await buildFontCatalog(); const indexHtml = templateHtml .replace(cardPlaceholder, cards) @@ -121,8 +100,8 @@ const indexHtml = templateHtml app.get("/", (c) => c.html(indexHtml)); -app.use("/fonts/*", serveStaticFromFs({ root: "." })); -app.use("/*", serveStaticFromFs({ root: "./public" })); +app.use("/fonts/*", serveStatic({ root: "." })); +app.use("/*", serveStatic({ root: "./public" })); const cssRoutes = async () => { const entries = await readdir(cssDir, { withFileTypes: true }); @@ -135,7 +114,7 @@ const cssRoutes = async () => { const filePath = join(cssDir, entry.name); app.get(route, async (c) => { - const css = await readFile(filePath, "utf8"); + const css = await Bun.file(filePath).text(); return c.text(css, 200, { "Content-Type": "text/css; charset=utf-8", }); @@ -145,11 +124,9 @@ const cssRoutes = async () => { await cssRoutes(); -const port = Number(process.env.PORT ?? 3000); +const port = Number(Bun.env.PORT ?? 3000); export default { fetch: app.fetch, port, }; - -export { app }; diff --git a/vercel.json b/vercel.json deleted file mode 100644 index 859305e..0000000 --- a/vercel.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "rewrites": [ - { - "source": "/(.*)", - "destination": "/api" - } - ] -}