Skip to content

Commit 5e5a243

Browse files
committed
Set proxy URI to domain proxy when possible
This will make the ports panel use it instead of the default path-based proxy.
1 parent 78282a1 commit 5e5a243

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/node/cli.ts

+3
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
571571
// Filter duplicate proxy domains and remove any leading `*.`.
572572
const proxyDomains = new Set((args["proxy-domain"] || []).map((d) => d.replace(/^\*\./, "")))
573573
args["proxy-domain"] = Array.from(proxyDomains)
574+
if (args["proxy-domain"].length > 0 && !process.env.VSCODE_PROXY_URI) {
575+
process.env.VSCODE_PROXY_URI = `{{port}}.${args["proxy-domain"][0]}`
576+
}
574577

575578
if (typeof args._ === "undefined") {
576579
args._ = []

test/unit/node/cli.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe("parser", () => {
4343
delete process.env.PASSWORD
4444
delete process.env.CS_DISABLE_FILE_DOWNLOADS
4545
delete process.env.CS_DISABLE_GETTING_STARTED_OVERRIDE
46+
delete process.env.VSCODE_PROXY_URI
4647
console.log = jest.fn()
4748
})
4849

@@ -457,6 +458,29 @@ describe("parser", () => {
457458
port: 8082,
458459
})
459460
})
461+
462+
it("should not set proxy uri without proxy domains", async () => {
463+
await setDefaults(parse([]))
464+
expect(process.env.VSCODE_PROXY_URI).toBeUndefined()
465+
})
466+
467+
it("should set proxy uri to first domain", async () => {
468+
await setDefaults(parse(["--proxy-domain", "coder.org"]),)
469+
expect(process.env.VSCODE_PROXY_URI).toEqual("{{port}}.coder.org")
470+
471+
await setDefaults(
472+
parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"]),
473+
)
474+
expect(process.env.VSCODE_PROXY_URI).toEqual("{{port}}.coder.com")
475+
})
476+
477+
it("should not override existing proxy uri", async () => {
478+
process.env.VSCODE_PROXY_URI = "foo"
479+
await setDefaults(
480+
parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"]),
481+
)
482+
expect(process.env.VSCODE_PROXY_URI).toEqual("foo")
483+
})
460484
})
461485

462486
describe("cli", () => {

0 commit comments

Comments
 (0)