Skip to content

Commit bb144f7

Browse files
committed
window.location.host and test fixes
1 parent c2e743e commit bb144f7

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

patches/proxy-uri.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
127127
+ if (config.productConfiguration && config.productConfiguration.proxyEndpointTemplate) {
128128
+ const renderedTemplate = config.productConfiguration.proxyEndpointTemplate
129129
+ .replace('{{port}}', localhostMatch.port.toString())
130-
+ .replace('{{host}}', window.location.hostname)
130+
+ .replace('{{host}}', window.location.host)
131131
+
132132
+ resolvedUri = URI.parse(new URL(renderedTemplate, window.location.href).toString())
133133
+ } else {

src/node/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const runCodeServer = async (
152152
args["proxy-domain"].forEach((domain) => logger.info(` - ${domain}`))
153153
}
154154
if(process.env.VSCODE_PROXY_URI) {
155-
logger.info(`using proxy uri in PORTS tab: ${process.env.VSCODE_PROXY_URI}`)
155+
logger.info(`Using proxy URI in PORTS tab: ${process.env.VSCODE_PROXY_URI}`)
156156
}
157157

158158
if (args.enable && args.enable.length > 0) {

src/node/routes/domainProxy.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ const proxyDomainToRegex = (matchString: string): RegExp => {
2222

2323
let proxyRegexes : RegExp[] = [];
2424
const proxyDomainsToRegex = (proxyDomains : string[]): RegExp[] => {
25-
if(proxyDomains.length != proxyRegexes.length) {
25+
if(proxyDomains.length !== proxyRegexes.length) {
2626
proxyRegexes = proxyDomains.map(proxyDomainToRegex);
2727
}
2828
return proxyRegexes;
2929
}
3030

3131
/**
32-
* Return the port if the request should be proxied. Anything that ends in a
33-
* proxy domain and has a *single* subdomain should be proxied. Anything else
34-
* should return `undefined` and will be handled as normal.
35-
*
36-
* For example if `coder.com` is specified `8080.coder.com` will be proxied
37-
* but `8080.test.coder.com` and `test.8080.coder.com` will not.
32+
* Return the port if the request should be proxied.
33+
*
34+
* The proxy-domain should be of format anyprefix-{{port}}-anysuffix.{{host}}, where {{host}} is optional
35+
* e.g. code-8080.domain.tld would match for code-{{port}}.domain.tld and code-{{port}}.{{host}}.
36+
*
3837
*/
3938
const maybeProxy = (req: Request): string | undefined => {
4039
let reqDomain = getHost(req);

test/unit/node/cli.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ describe("parser", () => {
413413
const defaultArgs = await setDefaults(args)
414414
expect(defaultArgs).toEqual({
415415
...defaults,
416-
"proxy-domain": ["coder.com", "coder.org"],
416+
"proxy-domain": ["{{port}}.coder.com", "{{port}}.coder.org"],
417417
})
418418
})
419419
it("should allow '=,$/' in strings", async () => {
@@ -466,14 +466,14 @@ describe("parser", () => {
466466

467467
it("should set proxy uri", async () => {
468468
await setDefaults(parse(["--proxy-domain", "coder.org"]))
469-
expect(process.env.VSCODE_PROXY_URI).toEqual("{{port}}.coder.org")
469+
expect(process.env.VSCODE_PROXY_URI).toEqual("//{{port}}.coder.org")
470470
})
471471

472472
it("should set proxy uri to first domain", async () => {
473473
await setDefaults(
474474
parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"]),
475475
)
476-
expect(process.env.VSCODE_PROXY_URI).toEqual("{{port}}.coder.com")
476+
expect(process.env.VSCODE_PROXY_URI).toEqual("//{{port}}.coder.com")
477477
})
478478

479479
it("should not override existing proxy uri", async () => {

0 commit comments

Comments
 (0)