Fix proxy and split server into modules #1

Merged
probablycorey merged 18 commits from probablycorey/fix-proxy-404s into main 2026-03-11 16:35:00 +00:00
Showing only changes of commit a344e293f1 - Show all commits

View File

@ -8,7 +8,7 @@ export interface WsData {
const upstreams = new Map<ServerWebSocket<WsData>, WebSocket>()
export function createProxy(socketPath: string, isHealthy: () => boolean, isRunning: () => boolean) {
function proxyFetch(req: Request): Promise<Response> | Response {
async function proxyFetch(req: Request): Promise<Response> {
const url = new URL(req.url)
if (url.pathname === '/ok') {
@ -21,11 +21,12 @@ export function createProxy(socketPath: string, isHealthy: () => boolean, isRunn
const hasBody = req.method !== 'GET' && req.method !== 'HEAD'
const headers = new Headers(req.headers)
headers.delete('accept-encoding')
const body = hasBody ? await req.arrayBuffer() : undefined
return fetch(`http://localhost${url.pathname}${url.search}`, {
method: req.method,
headers,
body: hasBody ? req.body : undefined,
body,
unix: socketPath,
}).then((r) => {
const respHeaders = new Headers(r.headers)