| 146 | const server = Bun.serve({ |
| 147 | port: options.port ?? 0, |
| 148 | async fetch(req) { |
| 149 | const url = new URL(req.url); |
| 150 | const path = url.pathname; |
| 151 | |
| 152 | if (path === "/" || path === "/host.html") { |
| 153 | const fixture = url.searchParams.get("fixture") || "gsap-heavy"; |
| 154 | const width = Number(url.searchParams.get("width") || "1920"); |
| 155 | const height = Number(url.searchParams.get("height") || "1080"); |
| 156 | const html = buildHostHtml(fixture, width, height); |
| 157 | return applyCacheHeaders( |
| 158 | new Response(html, { headers: { "Content-Type": "text/html; charset=utf-8" } }), |
| 159 | noCache, |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | if (path === "/player/hyperframes-player.global.js") { |
| 164 | return applyCacheHeaders(await readBunFile(PATHS.player), noCache); |
| 165 | } |
| 166 | |
| 167 | if (path === "/vendor/hyperframe.runtime.iife.js") { |
| 168 | return applyCacheHeaders(await readBunFile(PATHS.runtime), noCache); |
| 169 | } |
| 170 | |
| 171 | if (path === "/vendor/gsap.min.js") { |
| 172 | return applyCacheHeaders(await readBunFile(PATHS.gsap), noCache); |
| 173 | } |
| 174 | |
| 175 | if (path.startsWith("/fixtures/")) { |
| 176 | const rel = path.replace(/^\/fixtures\//, ""); |
| 177 | const filePath = join(PATHS.fixturesDir, rel); |
| 178 | if (!filePath.startsWith(PATHS.fixturesDir)) { |
| 179 | return new Response("Forbidden", { status: 403 }); |
| 180 | } |
| 181 | return applyCacheHeaders(await readBunFile(filePath), noCache); |
| 182 | } |
| 183 | |
| 184 | return new Response("Not found", { status: 404 }); |
| 185 | }, |
| 186 | }); |
| 187 | |
| 188 | // server.port is `number | undefined` in Bun's types (undefined only for unix-socket |