import { serve } from "bun"; import { readdir } from "fs/promises"; import { buildVibesHtml } from "../build"; import index from "./index.html"; const server = serve({ routes: { "/.well-known/atproto-did": async () => { return new Response("did:plc:ttdrpj45ibqunmfhdsb4zdwq", { headers: { "Content-Type": "text/plain", }, }); }, // Serve client-metadata.json for OAuth "/client-metadata.json": async () => { try { const file = Bun.file("public/client-metadata.json"); return new Response(file, { headers: { "Content-Type": "application/json" }, }); } catch { return new Response("File not found", { status: 404 }); } }, // Serve static files from public directory "/nekomata.png": async () => { try { const file = Bun.file("public/nekomata.png"); return new Response(file); } catch { return new Response("File not found", { status: 404 }); } }, "/vibes": async () => { const files = (await readdir("public/vibes")).filter((f) => f !== "index.html"); return new Response(buildVibesHtml(files), { headers: { "Content-Type": "text/html" } }); }, "/vibes/*": async (req) => { const url = new URL(req.url); const file = Bun.file(`public${url.pathname}`); if (await file.exists()) { return new Response(file); } return new Response("Not found", { status: 404 }); }, // Serve index.html for all unmatched routes. "/*": index, "/api/hello": { async GET(req) { return Response.json({ message: "Hello, world!", method: "GET", }); }, async PUT(req) { return Response.json({ message: "Hello, world!", method: "PUT", }); }, }, "/api/hello/:name": async req => { const name = req.params.name; return Response.json({ message: `Hello, ${name}!`, }); }, }, development: process.env.NODE_ENV !== "production" && { // Enable browser hot reloading in development hmr: true, // Echo console logs from the browser to the server console: true, }, }); console.log(`🚀 Server running at ${server.url}`);