From aaa6c279a116c22c5f06d52521de14f9aafbe588 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 2 Apr 2020 11:49:23 -0500 Subject: [PATCH] Use Set for proxy domains --- src/node/app/proxy.ts | 6 +++--- src/node/entry.ts | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/node/app/proxy.ts b/src/node/app/proxy.ts index 19812cc1..35421913 100644 --- a/src/node/app/proxy.ts +++ b/src/node/app/proxy.ts @@ -17,7 +17,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider /** * Proxy domains are stored here without the leading `*.` */ - public readonly proxyDomains: string[] + public readonly proxyDomains: Set private readonly proxy = proxy.createProxyServer({}) /** @@ -26,7 +26,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider */ public constructor(options: HttpProviderOptions, proxyDomains: string[] = []) { super(options) - this.proxyDomains = proxyDomains.map((d) => d.replace(/^\*\./, "")).filter((d, i, arr) => arr.indexOf(d) === i) + this.proxyDomains = new Set(proxyDomains.map((d) => d.replace(/^\*\./, ""))) this.proxy.on("error", (error) => logger.warn(error.message)) // Intercept the response to rewrite absolute redirects against the base path. this.proxy.on("proxyRes", (response, request: Request) => { @@ -124,7 +124,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider // There must be an exact match. const port = parts.shift() const proxyDomain = parts.join(".") - if (!port || !this.proxyDomains.includes(proxyDomain)) { + if (!port || !this.proxyDomains.has(proxyDomain)) { return undefined } diff --git a/src/node/entry.ts b/src/node/entry.ts index e4f59834..6df34b7c 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -94,10 +94,8 @@ const main = async (args: Args): Promise => { logger.info(" - Not serving HTTPS") } - if (proxy.proxyDomains.length === 1) { - logger.info(` - Proxying *.${proxy.proxyDomains[0]}`) - } else if (proxy.proxyDomains.length > 1) { - logger.info(" - Proxying the following domains:") + if (proxy.proxyDomains.size > 0) { + logger.info(` - Proxying the following domain${proxy.proxyDomains.size === 1 ? "" : "s"}:`) proxy.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`)) }