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 static files from public directory 15 "/nekomata.png": async () => { 16 try { 17 const file = Bun.file("public/nekomata.png"); 18 return new Response(file); 19 } catch { 20 return new Response("File not found", { status: 404 }); 21 } 22 }, 23 24 // Serve index.html for all unmatched routes. 25 "/*": index, 26 27 "/api/hello": { 28 async GET(req) { 29 return Response.json({ 30 message: "Hello, world!", 31 method: "GET", 32 }); 33 }, 34 async PUT(req) { 35 return Response.json({ 36 message: "Hello, world!", 37 method: "PUT", 38 }); 39 }, 40 }, 41 42 "/api/hello/:name": async req => { 43 const name = req.params.name; 44 return Response.json({ 45 message: `Hello, ${name}!`, 46 }); 47 }, 48 }, 49 50 development: process.env.NODE_ENV !== "production" && { 51 // Enable browser hot reloading in development 52 hmr: true, 53 54 // Echo console logs from the browser to the server 55 console: true, 56 }, 57}); 58 59console.log(`🚀 Server running at ${server.url}`);