mirror of
https://github.com/hex248/fonts.git
synced 2026-02-07 18:23:06 +00:00
removed vercel adjustments
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
import { handle } from "hono/vercel";
|
|
||||||
import { app } from "../src/server";
|
|
||||||
|
|
||||||
export default handle(app);
|
|
||||||
@@ -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 { join, parse } from "node:path";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { serveStatic } from "hono/serve-static";
|
import { serveStatic } from "hono/bun";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@@ -10,27 +10,6 @@ const templatePath = join("public", "index.html");
|
|||||||
const cardPlaceholder = "<!-- FONT_CARDS -->";
|
const cardPlaceholder = "<!-- FONT_CARDS -->";
|
||||||
const importPlaceholder = "/* FONT_IMPORT */";
|
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) =>
|
const escapeHtml = (value: string) =>
|
||||||
value
|
value
|
||||||
.replaceAll("&", "&")
|
.replaceAll("&", "&")
|
||||||
@@ -79,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 readFile(filePath, "utf8");
|
const css = await Bun.file(filePath).text();
|
||||||
const families = parseFontFamilies(css);
|
const families = parseFontFamilies(css);
|
||||||
|
|
||||||
if (families.length === 0) {
|
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 { cards, importCss } = await buildFontCatalog();
|
||||||
const indexHtml = templateHtml
|
const indexHtml = templateHtml
|
||||||
.replace(cardPlaceholder, cards)
|
.replace(cardPlaceholder, cards)
|
||||||
@@ -121,8 +100,8 @@ const indexHtml = templateHtml
|
|||||||
|
|
||||||
app.get("/", (c) => c.html(indexHtml));
|
app.get("/", (c) => c.html(indexHtml));
|
||||||
|
|
||||||
app.use("/fonts/*", serveStaticFromFs({ root: "." }));
|
app.use("/fonts/*", serveStatic({ root: "." }));
|
||||||
app.use("/*", serveStaticFromFs({ root: "./public" }));
|
app.use("/*", serveStatic({ root: "./public" }));
|
||||||
|
|
||||||
const cssRoutes = async () => {
|
const cssRoutes = async () => {
|
||||||
const entries = await readdir(cssDir, { withFileTypes: true });
|
const entries = await readdir(cssDir, { withFileTypes: true });
|
||||||
@@ -135,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 readFile(filePath, "utf8");
|
const css = await Bun.file(filePath).text();
|
||||||
return c.text(css, 200, {
|
return c.text(css, 200, {
|
||||||
"Content-Type": "text/css; charset=utf-8",
|
"Content-Type": "text/css; charset=utf-8",
|
||||||
});
|
});
|
||||||
@@ -145,11 +124,9 @@ const cssRoutes = async () => {
|
|||||||
|
|
||||||
await cssRoutes();
|
await cssRoutes();
|
||||||
|
|
||||||
const port = Number(process.env.PORT ?? 3000);
|
const port = Number(Bun.env.PORT ?? 3000);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fetch: app.fetch,
|
fetch: app.fetch,
|
||||||
port,
|
port,
|
||||||
};
|
};
|
||||||
|
|
||||||
export { app };
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"rewrites": [
|
|
||||||
{
|
|
||||||
"source": "/(.*)",
|
|
||||||
"destination": "/api"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user