1import { serve } from "bun"; 2import index from "./index.html"; 3 4const server = serve({ 5 routes: { 6 "/.well-known/atproto-did": async () => { 7 return new Response("did:plc:ttdrpj45ibqunmfhdsb4zdwq", { 8 headers: { 9 "Content-Type": "text/plain", 10 }, 11 }); 12 }, 13 14 // Serve client-metadata.json for OAuth 15 "/client-metadata.json": async () => { 16 try { 17 const file = Bun.file("public/client-metadata.json"); 18 return new Response(file, { 19 headers: { "Content-Type": "application/json" }, 20 }); 21 } catch { 22 return new Response("File not found", { status: 404 }); 23 } 24 }, 25 26 // Serve static files from public directory 27 "/nekomata.png": async () => { 28 try { 29 const file = Bun.file("public/nekomata.png"); 30 return new Response(file); 31 } catch { 32 return new Response("File not found", { status: 404 }); 33 } 34 }, 35 36 // Serve index.html for all unmatched routes. 37 "/*": index, 38 39 "/api/hello": { 40 async GET(req) { 41 return Response.json({ 42 message: "Hello, world!", 43 method: "GET", 44 }); 45 }, 46 async PUT(req) { 47 return Response.json({ 48 message: "Hello, world!", 49 method: "PUT", 50 }); 51 }, 52 }, 53 54 "/api/hello/:name": async req => { 55 const name = req.params.name; 56 return Response.json({ 57 message: `Hello, ${name}!`, 58 }); 59 }, 60 }, 61 62 development: process.env.NODE_ENV !== "production" && { 63 // Enable browser hot reloading in development 64 hmr: true, 65 66 // Echo console logs from the browser to the server 67 console: true, 68 }, 69}); 70 71console.log(`🚀 Server running at ${server.url}`);