From f169e3ac665c9180455f66a5acea0f2257837c66 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 11 Jan 2021 13:17:45 -0500 Subject: [PATCH] pathProxy.ts: Implement --proxy-path-passthrough Closes #2222 --- src/node/cli.ts | 5 +++++ src/node/routes/pathProxy.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index 1653e87a7..5a0e4473e 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -50,6 +50,7 @@ export interface Args extends VsArgs { "show-versions"?: boolean "uninstall-extension"?: string[] "proxy-domain"?: string[] + "proxy-path-passthrough"?: boolean locale?: string _: string[] "reuse-window"?: boolean @@ -172,6 +173,10 @@ const options: Options> = { "uninstall-extension": { type: "string[]", description: "Uninstall a VS Code extension by id." }, "show-versions": { type: "boolean", description: "Show VS Code extension versions." }, "proxy-domain": { type: "string[]", description: "Domain used for proxying ports." }, + "proxy-path-passthrough": { + type: "boolean", + description: "Whether the path proxy should leave the /proxy/ in the request path when proxying.", + }, "ignore-last-opened": { type: "boolean", short: "e", diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index 152402195..9554a006d 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -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), }) })