f5cf3fd331
This breaks --proxy-path-passthrough However, we still need this when that code is disabled as many apps will issue absolute redirects and expect the proxy to rewrite as appropriate. e.g. Go's http.Redirect will rewrite relative redirects as absolute! See https://golang.org/pkg/net/http/#Redirect
19 lines
631 B
TypeScript
19 lines
631 B
TypeScript
import proxyServer from "http-proxy"
|
|
import { HttpCode } from "../common/http"
|
|
|
|
export const proxy = proxyServer.createProxyServer({})
|
|
|
|
proxy.on("error", (error, _, res) => {
|
|
res.writeHead(HttpCode.ServerError)
|
|
res.end(error.message)
|
|
})
|
|
|
|
// Intercept the response to rewrite absolute redirects against the base path.
|
|
// Is disabled when the request has no base path which means --proxy-path-passthrough has
|
|
// been enabled.
|
|
proxy.on("proxyRes", (res, req) => {
|
|
if (res.headers.location && res.headers.location.startsWith("/") && (req as any).base) {
|
|
res.headers.location = (req as any).base + res.headers.location
|
|
}
|
|
})
|