From 9976362840c7474d3fe84f3953475c8088bf6d53 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Wed, 4 Feb 2026 15:13:15 +0000 Subject: [PATCH] server --- .gitignore | 8 ++++++++ bun.lock | 24 ++++++++++++++++++++++++ css/basteleur.css | 32 ++++++++++++++------------------ package.json | 13 +++++++++++++ src/server.ts | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 .gitignore create mode 100644 bun.lock create mode 100644 package.json create mode 100644 src/server.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4126c8b --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +node_modules +.DS_Store +*.log +dist +build +coverage +.env +.env.* diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..1a34753 --- /dev/null +++ b/bun.lock @@ -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=="], + } +} diff --git a/css/basteleur.css b/css/basteleur.css index a01599e..4935099 100644 --- a/css/basteleur.css +++ b/css/basteleur.css @@ -1,23 +1,19 @@ @font-face { - font-family: "Basteleur"; - src: - url("/fonts/Basteleur-Bold.woff2") format("woff2"), - url("/fonts/Basteleur-Bold.woff") format("woff"); - font-weight: 700; - font-style: normal; - font-display: swap; + font-family: "Basteleur"; + src: + url("/fonts/Basteleur-Bold.woff2") format("woff2"), + url("/fonts/Basteleur-Bold.woff") format("woff"); + font-weight: 700; + font-style: normal; + font-display: swap; } @font-face { - font-family: "Basteleur"; - src: - url("/fonts/Basteleur-Moonlight.woff2") format("woff2"), - url("/fonts/Basteleur-Moonlight.woff") format("woff"); - font-weight: 400; - font-style: normal; - font-display: swap; + font-family: "Basteleur"; + src: + url("/fonts/Basteleur-Moonlight.woff2") format("woff2"), + url("/fonts/Basteleur-Moonlight.woff") format("woff"); + font-weight: 400; + font-style: normal; + font-display: swap; } - - - - diff --git a/package.json b/package.json new file mode 100644 index 0000000..58eba68 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..ef4b92c --- /dev/null +++ b/src/server.ts @@ -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, +};