From 0f59978f41787c5b6e93aede0893c298dbbfc830 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 27 Oct 2021 10:56:40 +0200 Subject: [PATCH] fix(@nguniversal/builders): correctly handle multiple proxies Closes #2411 --- modules/builders/src/ssr-dev-server/index.ts | 29 ++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/builders/src/ssr-dev-server/index.ts b/modules/builders/src/ssr-dev-server/index.ts index 21af42c01..30c83393d 100644 --- a/modules/builders/src/ssr-dev-server/index.ts +++ b/modules/builders/src/ssr-dev-server/index.ts @@ -348,19 +348,26 @@ function getProxyConfig(root: string, proxyConfig: string): browserSync.Middlewa } const proxies = Array.isArray(proxySettings) ? proxySettings : [proxySettings]; - - return proxies.map((proxy) => { - const keys = Object.keys(proxy); - const context = keys[0]; - - if (keys.length === 1 || typeof context === 'string') { - const normalizedContext = context.replace(/^\*$/, '**').replace(/\/\*$/, ''); - - return createProxyMiddleware(normalizedContext, proxy[context]) as any; + const createdProxies = []; + + for (const proxy of proxies) { + for (const [key, context] of Object.entries(proxy)) { + if (typeof key === 'string') { + createdProxies.push( + createProxyMiddleware( + key.replace(/^\*$/, '**').replace(/\/\*$/, ''), + context as any, + ) as browserSync.MiddlewareHandler, + ); + } else { + createdProxies.push( + createProxyMiddleware(key, context as any) as browserSync.MiddlewareHandler, + ); + } } + } - return createProxyMiddleware(proxy) as any; - }); + return createdProxies; } export default createBuilder(execute);