Spaces:
Paused
Paused
| /** | |
| * Bun server: HTML import (bundles src/app.js + src/style.css and everything | |
| * they import) + static assets from public/ + a tiny /api/config so the | |
| * client's boot() doesn't log a 404 in direct-connect mode. | |
| * | |
| * This rebuild ships direct-connect only: no /api/session load-balancer | |
| * proxy (that needs backend credentials this rebuild doesn't have). Point | |
| * Settings -> "Direct server URL" at a running s2s realtime endpoint | |
| * (ws://.../v1/realtime) to talk to it. | |
| */ | |
| import index from "./index.html"; | |
| const PUBLIC_DIR = `${import.meta.dir}/public`; | |
| Bun.serve({ | |
| port: Number(process.env.PORT ?? 7860), | |
| routes: { | |
| "/": index, | |
| "/api/config": () => | |
| Response.json({ lb: false, allowDirect: true }), | |
| }, | |
| async fetch(req) { | |
| const url = new URL(req.url); | |
| // Static assets: public/worklets/*, public/vendor/*, public/avatars/*. | |
| const path = decodeURIComponent(url.pathname); | |
| if (path === "/" || path.startsWith("/api/")) { | |
| return new Response("Not found", { status: 404 }); | |
| } | |
| const file = Bun.file(`${PUBLIC_DIR}${path}`); | |
| if (await file.exists()) { | |
| return new Response(file); | |
| } | |
| return new Response("Not found", { status: 404 }); | |
| }, | |
| development: { | |
| hmr: true, | |
| console: true, | |
| }, | |
| }); | |
| console.log(`Gemma Avatar listening on http://localhost:${process.env.PORT ?? 7860}`); | |