From bfe63259e36df7242520fc3f09f750ec3ea83c04 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Wed, 4 Feb 2026 16:08:44 +0000 Subject: [PATCH] serverless for vercel --- api/index.ts | 4 ++++ src/server.ts | 14 ++++++++------ vercel.json | 8 ++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 api/index.ts create mode 100644 vercel.json diff --git a/api/index.ts b/api/index.ts new file mode 100644 index 0000000..50a7908 --- /dev/null +++ b/api/index.ts @@ -0,0 +1,4 @@ +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 2f156ae..ea500db 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,7 +1,7 @@ -import { readdir } from "node:fs/promises"; +import { readFile, readdir } from "node:fs/promises"; import { join, parse } from "node:path"; import { Hono } from "hono"; -import { serveStatic } from "hono/bun"; +import { serveStatic } from "hono/serve-static"; const app = new Hono(); @@ -58,7 +58,7 @@ const buildFontCatalog = async () => { const baseName = parse(fileName).name; const route = `/${baseName}`; const filePath = join(cssDir, fileName); - const css = await Bun.file(filePath).text(); + const css = await readFile(filePath, "utf8"); const families = parseFontFamilies(css); if (families.length === 0) { @@ -92,7 +92,7 @@ const buildFontCatalog = async () => { }; }; -const templateHtml = await Bun.file(templatePath).text(); +const templateHtml = await readFile(templatePath, "utf8"); const { cards, importCss } = await buildFontCatalog(); const indexHtml = templateHtml .replace(cardPlaceholder, cards) @@ -114,7 +114,7 @@ const cssRoutes = async () => { const filePath = join(cssDir, entry.name); app.get(route, async (c) => { - const css = await Bun.file(filePath).text(); + const css = await readFile(filePath, "utf8"); return c.text(css, 200, { "Content-Type": "text/css; charset=utf-8", }); @@ -124,9 +124,11 @@ const cssRoutes = async () => { await cssRoutes(); -const port = Number(Bun.env.PORT ?? 3000); +const port = Number(process.env.PORT ?? 3000); export default { fetch: app.fetch, port, }; + +export { app }; diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..859305e --- /dev/null +++ b/vercel.json @@ -0,0 +1,8 @@ +{ + "rewrites": [ + { + "source": "/(.*)", + "destination": "/api" + } + ] +}