Skip to content

Commit f5cf3fd

Browse files
committed
proxy.ts: Do not always rewrite redirects against the base path
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
1 parent 5446e0a commit f5cf3fd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node/proxy.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ proxy.on("error", (error, _, res) => {
99
})
1010

1111
// Intercept the response to rewrite absolute redirects against the base path.
12+
// Is disabled when the request has no base path which means --proxy-path-passthrough has
13+
// been enabled.
1214
proxy.on("proxyRes", (res, req) => {
1315
if (res.headers.location && res.headers.location.startsWith("/") && (req as any).base) {
1416
res.headers.location = (req as any).base + res.headers.location

src/node/routes/pathProxy.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ router.all("/(:port)(/*)?", (req, res) => {
2828
throw new HttpError("Unauthorized", HttpCode.Unauthorized)
2929
}
3030

31-
// Absolute redirects need to be based on the subpath when rewriting.
32-
;(req as any).base = `${req.baseUrl}/${req.params.port}`
31+
if (!req.args["proxy-path-passthrough"]) {
32+
// Absolute redirects need to be based on the subpath when rewriting.
33+
;(req as any).base = `${req.baseUrl}/${req.params.port}`
34+
}
3335

3436
proxy.web(req, res, {
3537
ignorePath: true,

0 commit comments

Comments
 (0)