Skip to content

Commit f169e3a

Browse files
committed
pathProxy.ts: Implement --proxy-path-passthrough
Closes #2222
1 parent eae285c commit f169e3a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/node/cli.ts

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface Args extends VsArgs {
5050
"show-versions"?: boolean
5151
"uninstall-extension"?: string[]
5252
"proxy-domain"?: string[]
53+
"proxy-path-passthrough"?: boolean
5354
locale?: string
5455
_: string[]
5556
"reuse-window"?: boolean
@@ -172,6 +173,10 @@ const options: Options<Required<Args>> = {
172173
"uninstall-extension": { type: "string[]", description: "Uninstall a VS Code extension by id." },
173174
"show-versions": { type: "boolean", description: "Show VS Code extension versions." },
174175
"proxy-domain": { type: "string[]", description: "Domain used for proxying ports." },
176+
"proxy-path-passthrough": {
177+
type: "boolean",
178+
description: "Whether the path proxy should leave the /proxy/<port> in the request path when proxying.",
179+
},
175180
"ignore-last-opened": {
176181
type: "boolean",
177182
short: "e",

src/node/routes/pathProxy.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { Router as WsRouter } from "../wsRouter"
88

99
export const router = Router()
1010

11-
const getProxyTarget = (req: Request, rewrite: boolean): string => {
12-
if (rewrite) {
13-
const query = qs.stringify(req.query)
14-
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
11+
const getProxyTarget = (req: Request, passthroughPath: boolean): string => {
12+
if (passthroughPath) {
13+
return `http://0.0.0.0:${req.params.port}/${req.originalUrl}`
1514
}
16-
return `http://0.0.0.0:${req.params.port}/${req.originalUrl}`
15+
const query = qs.stringify(req.query)
16+
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
1717
}
1818

1919
router.all("/(:port)(/*)?", (req, res) => {
@@ -33,7 +33,7 @@ router.all("/(:port)(/*)?", (req, res) => {
3333

3434
proxy.web(req, res, {
3535
ignorePath: true,
36-
target: getProxyTarget(req, true),
36+
target: getProxyTarget(req, req.args["proxy-path-passthrough"] || false),
3737
})
3838
})
3939

@@ -42,6 +42,6 @@ export const wsRouter = WsRouter()
4242
wsRouter.ws("/(:port)(/*)?", ensureAuthenticated, (req) => {
4343
proxy.ws(req, req.ws, req.head, {
4444
ignorePath: true,
45-
target: getProxyTarget(req, true),
45+
target: getProxyTarget(req, req.args["proxy-path-passthrough"] || false),
4646
})
4747
})

0 commit comments

Comments
 (0)