repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
The Living OS cockpit
stars
latest
clone command
git clone gitlawb://did:key:z6Mku78K...XywC/living-os-cockp...git clone gitlawb://did:key:z6Mku78K.../living-os-cockp...59751530feat: surface worker supervisor health in live work5h ago| #1 | import { NextRequest } from 'next/server'; |
| #2 | |
| #3 | function bridgePortForHost(host: string): number { |
| #4 | return host.startsWith('maaxx.') ? 3101 : 3100; |
| #5 | } |
| #6 | |
| #7 | export async function proxyBridgeRequest(req: NextRequest, path: string) { |
| #8 | const host = req.headers.get('host') ?? ''; |
| #9 | const port = bridgePortForHost(host); |
| #10 | const url = new URL(req.url); |
| #11 | const target = `http://127.0.0.1:${port}${path}${url.search}`; |
| #12 | |
| #13 | const headers = new Headers(); |
| #14 | const contentType = req.headers.get('content-type'); |
| #15 | const accept = req.headers.get('accept'); |
| #16 | if (contentType) headers.set('content-type', contentType); |
| #17 | if (accept) headers.set('accept', accept); |
| #18 | |
| #19 | const init: RequestInit = { |
| #20 | method: req.method, |
| #21 | headers, |
| #22 | cache: 'no-store', |
| #23 | }; |
| #24 | |
| #25 | if (!['GET', 'HEAD'].includes(req.method)) { |
| #26 | init.body = await req.arrayBuffer(); |
| #27 | } |
| #28 | |
| #29 | const upstream = await fetch(target, init); |
| #30 | const responseHeaders = new Headers(upstream.headers); |
| #31 | responseHeaders.delete('content-encoding'); |
| #32 | responseHeaders.delete('transfer-encoding'); |
| #33 | |
| #34 | return new Response(upstream.body, { |
| #35 | status: upstream.status, |
| #36 | statusText: upstream.statusText, |
| #37 | headers: responseHeaders, |
| #38 | }); |
| #39 | } |
| #40 |