serverless for vercel

This commit is contained in:
2026-02-04 16:08:44 +00:00
parent b485f24e48
commit bfe63259e3
3 changed files with 20 additions and 6 deletions

4
api/index.ts Normal file
View File

@@ -0,0 +1,4 @@
import { handle } from "hono/vercel";
import { app } from "../src/server";
export default handle(app);

View File

@@ -1,7 +1,7 @@
import { readdir } from "node:fs/promises"; import { readFile, readdir } from "node:fs/promises";
import { join, parse } from "node:path"; import { join, parse } from "node:path";
import { Hono } from "hono"; import { Hono } from "hono";
import { serveStatic } from "hono/bun"; import { serveStatic } from "hono/serve-static";
const app = new Hono(); const app = new Hono();
@@ -58,7 +58,7 @@ const buildFontCatalog = async () => {
const baseName = parse(fileName).name; const baseName = parse(fileName).name;
const route = `/${baseName}`; const route = `/${baseName}`;
const filePath = join(cssDir, fileName); const filePath = join(cssDir, fileName);
const css = await Bun.file(filePath).text(); const css = await readFile(filePath, "utf8");
const families = parseFontFamilies(css); const families = parseFontFamilies(css);
if (families.length === 0) { 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 { cards, importCss } = await buildFontCatalog();
const indexHtml = templateHtml const indexHtml = templateHtml
.replace(cardPlaceholder, cards) .replace(cardPlaceholder, cards)
@@ -114,7 +114,7 @@ const cssRoutes = async () => {
const filePath = join(cssDir, entry.name); const filePath = join(cssDir, entry.name);
app.get(route, async (c) => { app.get(route, async (c) => {
const css = await Bun.file(filePath).text(); const css = await readFile(filePath, "utf8");
return c.text(css, 200, { return c.text(css, 200, {
"Content-Type": "text/css; charset=utf-8", "Content-Type": "text/css; charset=utf-8",
}); });
@@ -124,9 +124,11 @@ const cssRoutes = async () => {
await cssRoutes(); await cssRoutes();
const port = Number(Bun.env.PORT ?? 3000); const port = Number(process.env.PORT ?? 3000);
export default { export default {
fetch: app.fetch, fetch: app.fetch,
port, port,
}; };
export { app };

8
vercel.json Normal file
View File

@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/api"
}
]
}