mirror of
https://github.com/hex248/fonts.git
synced 2026-02-08 02:33:03 +00:00
fixes for vercel
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import { readFile, readdir, stat } from "node:fs/promises";
|
||||
import { join, parse } from "node:path";
|
||||
import { Hono } from "hono";
|
||||
import { serveStatic } from "hono/serve-static";
|
||||
import { serveStatic } from "hono/middleware/serve-static";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
@@ -10,6 +10,27 @@ const templatePath = join("public", "index.html");
|
||||
const cardPlaceholder = "<!-- FONT_CARDS -->";
|
||||
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("&", "&")
|
||||
@@ -100,8 +121,8 @@ const indexHtml = templateHtml
|
||||
|
||||
app.get("/", (c) => c.html(indexHtml));
|
||||
|
||||
app.use("/fonts/*", serveStatic({ root: "." }));
|
||||
app.use("/*", serveStatic({ root: "./public" }));
|
||||
app.use("/fonts/*", serveStaticFromFs({ root: "." }));
|
||||
app.use("/*", serveStaticFromFs({ root: "./public" }));
|
||||
|
||||
const cssRoutes = async () => {
|
||||
const entries = await readdir(cssDir, { withFileTypes: true });
|
||||
|
||||
Reference in New Issue
Block a user