Skip to content

Commit

Permalink
pathProxy.ts: Implement --proxy-path-passthrough
Browse files Browse the repository at this point in the history
Closes coder#2222
  • Loading branch information
nhooyr committed Jan 14, 2021
1 parent aa7d5c1 commit 12fcacc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,6 +173,10 @@ const options: Options<Required<Args>> = {
"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/<port> in the request path when proxying.",
},
"ignore-last-opened": {
type: "boolean",
short: "e",
Expand Down
14 changes: 7 additions & 7 deletions src/node/routes/pathProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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),
})
})

Expand All @@ -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),
})
})

0 comments on commit 12fcacc

Please sign in to comment.