mirror of
https://github.com/hex248/fonts.git
synced 2026-02-07 18:23:06 +00:00
server
This commit is contained in:
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
*.log
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
coverage
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
24
bun.lock
Normal file
24
bun.lock
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 1,
|
||||||
|
"workspaces": {
|
||||||
|
"": {
|
||||||
|
"name": "fonts-ob-server",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/bun": "^1.3.8",
|
||||||
|
"hono": "^4.6.0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"packages": {
|
||||||
|
"@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
|
||||||
|
|
||||||
|
"@types/node": ["@types/node@25.2.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w=="],
|
||||||
|
|
||||||
|
"bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
|
||||||
|
|
||||||
|
"hono": ["hono@4.11.7", "", {}, "sha512-l7qMiNee7t82bH3SeyUCt9UF15EVmaBvsppY2zQtrbIhl/yzBTny+YUxsVjSjQ6gaqaeVtZmGocom8TzBlA4Yw=="],
|
||||||
|
|
||||||
|
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,3 @@
|
|||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
package.json
Normal file
13
package.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "fonts-ob-server",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "bun run src/server.ts",
|
||||||
|
"start": "bun run src/server.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/bun": "^1.3.8",
|
||||||
|
"hono": "^4.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/server.ts
Normal file
39
src/server.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { readdir } from "node:fs/promises";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { Hono } from "hono";
|
||||||
|
import { serveStatic } from "hono/bun";
|
||||||
|
|
||||||
|
const app = new Hono();
|
||||||
|
|
||||||
|
app.use("/fonts/*", serveStatic({ root: "." }));
|
||||||
|
app.use("/*", serveStatic({ root: "./public" }));
|
||||||
|
|
||||||
|
const cssDir = "css";
|
||||||
|
|
||||||
|
const cssRoutes = async () => {
|
||||||
|
const entries = await readdir(cssDir, { withFileTypes: true });
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.isFile() || !entry.name.endsWith(".css")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const route = `/${entry.name.replace(".css", "")}`;
|
||||||
|
const filePath = join(cssDir, entry.name);
|
||||||
|
|
||||||
|
app.get(route, async (c) => {
|
||||||
|
const css = await Bun.file(filePath).text();
|
||||||
|
return c.text(css, 200, {
|
||||||
|
"Content-Type": "text/css; charset=utf-8",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await cssRoutes();
|
||||||
|
|
||||||
|
const port = Number(Bun.env.PORT ?? 3000);
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fetch: app.fetch,
|
||||||
|
port,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user