Archived
1
0

pathProxy.ts: Implement --proxy-path-passthrough

Closes #2222
This commit is contained in:
Anmol Sethi
2021-01-11 13:17:45 -05:00
parent eae285cf93
commit f169e3ac66
2 changed files with 12 additions and 7 deletions

View File

@ -8,12 +8,12 @@ import { Router as WsRouter } from "../wsRouter"
export const router = Router()
const getProxyTarget = (req: Request, rewrite: boolean): string => {
if (rewrite) {
const query = qs.stringify(req.query)
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
const getProxyTarget = (req: Request, passthroughPath: boolean): string => {
if (passthroughPath) {
return `http://0.0.0.0:${req.params.port}/${req.originalUrl}`
}
return `http://0.0.0.0:${req.params.port}/${req.originalUrl}`
const query = qs.stringify(req.query)
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
}
router.all("/(:port)(/*)?", (req, res) => {
@ -33,7 +33,7 @@ router.all("/(:port)(/*)?", (req, res) => {
proxy.web(req, res, {
ignorePath: true,
target: getProxyTarget(req, true),
target: getProxyTarget(req, req.args["proxy-path-passthrough"] || false),
})
})
@ -42,6 +42,6 @@ export const wsRouter = WsRouter()
wsRouter.ws("/(:port)(/*)?", ensureAuthenticated, (req) => {
proxy.ws(req, req.ws, req.head, {
ignorePath: true,
target: getProxyTarget(req, true),
target: getProxyTarget(req, req.args["proxy-path-passthrough"] || false),
})
})