Use Set for proxy domains
This commit is contained in:
parent
498becd11f
commit
aaa6c279a1
@ -17,7 +17,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
/**
|
/**
|
||||||
* Proxy domains are stored here without the leading `*.`
|
* Proxy domains are stored here without the leading `*.`
|
||||||
*/
|
*/
|
||||||
public readonly proxyDomains: string[]
|
public readonly proxyDomains: Set<string>
|
||||||
private readonly proxy = proxy.createProxyServer({})
|
private readonly proxy = proxy.createProxyServer({})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,7 +26,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
*/
|
*/
|
||||||
public constructor(options: HttpProviderOptions, proxyDomains: string[] = []) {
|
public constructor(options: HttpProviderOptions, proxyDomains: string[] = []) {
|
||||||
super(options)
|
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))
|
this.proxy.on("error", (error) => logger.warn(error.message))
|
||||||
// Intercept the response to rewrite absolute redirects against the base path.
|
// Intercept the response to rewrite absolute redirects against the base path.
|
||||||
this.proxy.on("proxyRes", (response, request: Request) => {
|
this.proxy.on("proxyRes", (response, request: Request) => {
|
||||||
@ -124,7 +124,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
// There must be an exact match.
|
// There must be an exact match.
|
||||||
const port = parts.shift()
|
const port = parts.shift()
|
||||||
const proxyDomain = parts.join(".")
|
const proxyDomain = parts.join(".")
|
||||||
if (!port || !this.proxyDomains.includes(proxyDomain)) {
|
if (!port || !this.proxyDomains.has(proxyDomain)) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,10 +94,8 @@ const main = async (args: Args): Promise<void> => {
|
|||||||
logger.info(" - Not serving HTTPS")
|
logger.info(" - Not serving HTTPS")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy.proxyDomains.length === 1) {
|
if (proxy.proxyDomains.size > 0) {
|
||||||
logger.info(` - Proxying *.${proxy.proxyDomains[0]}`)
|
logger.info(` - Proxying the following domain${proxy.proxyDomains.size === 1 ? "" : "s"}:`)
|
||||||
} else if (proxy.proxyDomains.length > 1) {
|
|
||||||
logger.info(" - Proxying the following domains:")
|
|
||||||
proxy.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
|
proxy.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user