proxy fixes
This commit is contained in:
parent
caac6877d7
commit
1dc7b76b31
|
|
@ -38,12 +38,20 @@ export async function proxySubdomain(subdomain: string, req: Request): Promise<R
|
||||||
|
|
||||||
const url = new URL(req.url)
|
const url = new URL(req.url)
|
||||||
const target = `http://localhost:${app.port}${url.pathname}${url.search}`
|
const target = `http://localhost:${app.port}${url.pathname}${url.search}`
|
||||||
|
const hasBody = req.method !== 'GET' && req.method !== 'HEAD'
|
||||||
|
const body = hasBody ? await req.arrayBuffer() : undefined
|
||||||
|
|
||||||
|
const headers = new Headers(req.headers)
|
||||||
|
headers.delete('host')
|
||||||
|
headers.delete('connection')
|
||||||
|
headers.delete('keep-alive')
|
||||||
|
headers.delete('transfer-encoding')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await fetch(target, {
|
return await fetch(target, {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
headers: req.headers,
|
headers,
|
||||||
body: req.method !== 'GET' && req.method !== 'HEAD' ? req.body : undefined,
|
body,
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Proxy error for ${subdomain}:`, e)
|
console.error(`Proxy error for ${subdomain}:`, e)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user