Skip to content

Commit af6fa7e

Browse files
committed
Use Set for proxy domains
1 parent 5277ca6 commit af6fa7e

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/node/app/proxy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
1717
/**
1818
* Proxy domains are stored here without the leading `*.`
1919
*/
20-
public readonly proxyDomains: string[]
20+
public readonly proxyDomains: Set<string>
2121
private readonly proxy = proxy.createProxyServer({})
2222

2323
/**
@@ -26,7 +26,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
2626
*/
2727
public constructor(options: HttpProviderOptions, proxyDomains: string[] = []) {
2828
super(options)
29-
this.proxyDomains = proxyDomains.map((d) => d.replace(/^\*\./, "")).filter((d, i, arr) => arr.indexOf(d) === i)
29+
this.proxyDomains = new Set(proxyDomains.map((d) => d.replace(/^\*\./, "")))
3030
this.proxy.on("error", (error) => logger.warn(error.message))
3131
// Intercept the response to rewrite absolute redirects against the base path.
3232
this.proxy.on("proxyRes", (response, request: Request) => {
@@ -124,7 +124,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
124124
// There must be an exact match.
125125
const port = parts.shift()
126126
const proxyDomain = parts.join(".")
127-
if (!port || !this.proxyDomains.includes(proxyDomain)) {
127+
if (!port || !this.proxyDomains.has(proxyDomain)) {
128128
return undefined
129129
}
130130

src/node/entry.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ const main = async (args: Args): Promise<void> => {
9494
logger.info(" - Not serving HTTPS")
9595
}
9696

97-
if (proxy.proxyDomains.length === 1) {
98-
logger.info(` - Proxying *.${proxy.proxyDomains[0]}`)
99-
} else if (proxy.proxyDomains.length > 1) {
100-
logger.info(" - Proxying the following domains:")
97+
if (proxy.proxyDomains.size > 0) {
98+
logger.info(` - Proxying the following domain${proxy.proxyDomains.size === 1 ? "" : "s"}:`)
10199
proxy.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
102100
}
103101

0 commit comments

Comments
 (0)