Set proxy URI to domain proxy when possible (#6115)

This will make the ports panel use it instead of the default path-based
proxy.
This commit is contained in:
Asher 2023-03-30 12:01:49 -08:00 committed by GitHub
parent a44bd71043
commit c995988b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -571,6 +571,9 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
// Filter duplicate proxy domains and remove any leading `*.`.
const proxyDomains = new Set((args["proxy-domain"] || []).map((d) => d.replace(/^\*\./, "")))
args["proxy-domain"] = Array.from(proxyDomains)
if (args["proxy-domain"].length > 0 && !process.env.VSCODE_PROXY_URI) {
process.env.VSCODE_PROXY_URI = `{{port}}.${args["proxy-domain"][0]}`
}
if (typeof args._ === "undefined") {
args._ = []

View File

@ -43,6 +43,7 @@ describe("parser", () => {
delete process.env.PASSWORD
delete process.env.CS_DISABLE_FILE_DOWNLOADS
delete process.env.CS_DISABLE_GETTING_STARTED_OVERRIDE
delete process.env.VSCODE_PROXY_URI
console.log = jest.fn()
})
@ -457,6 +458,31 @@ describe("parser", () => {
port: 8082,
})
})
it("should not set proxy uri", async () => {
await setDefaults(parse([]))
expect(process.env.VSCODE_PROXY_URI).toBeUndefined()
})
it("should set proxy uri", async () => {
await setDefaults(parse(["--proxy-domain", "coder.org"]))
expect(process.env.VSCODE_PROXY_URI).toEqual("{{port}}.coder.org")
})
it("should set proxy uri to first domain", async () => {
await setDefaults(
parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"]),
)
expect(process.env.VSCODE_PROXY_URI).toEqual("{{port}}.coder.com")
})
it("should not override existing proxy uri", async () => {
process.env.VSCODE_PROXY_URI = "foo"
await setDefaults(
parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"]),
)
expect(process.env.VSCODE_PROXY_URI).toEqual("foo")
})
})
describe("cli", () => {