Skip to content

Commit

Permalink
build: update dependency http-proxy-middleware to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Apr 10, 2024
1 parent d482c65 commit 733fba2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"express": "4.19.2",
"fast-glob": "3.3.2",
"http-proxy": "^1.18.1",
"http-proxy-middleware": "2.0.6",
"http-proxy-middleware": "3.0.0",
"https-proxy-agent": "7.0.4",
"husky": "9.0.11",
"ini": "4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"esbuild-wasm": "0.20.2",
"fast-glob": "3.3.2",
"https-proxy-agent": "7.0.4",
"http-proxy-middleware": "2.0.6",
"http-proxy-middleware": "3.0.0",
"inquirer": "9.2.17",
"jsonc-parser": "3.2.1",
"karma-source-map-support": "1.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ export async function setupServer(
const proxy = await loadProxyConfiguration(
serverOptions.workspaceRoot,
serverOptions.proxyConfig,
true,
);

// dynamically import Vite for ESM compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,25 @@ async function initBrowserSync(
const { createProxyMiddleware } = await import('http-proxy-middleware');

// Remove leading slash
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
(bsOptions.scriptPath = (p) => p.substring(1)),
(bsOptions.middleware = [
createProxyMiddleware(defaultSocketIoPath, {
target: url.format({
protocol: 'http',
hostname: host,
port: bsPort,
pathname: path,
}),
ws: true,
logLevel: 'silent',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any,
]);
bsOptions.scriptPath = (p) => p.substring(1);

bsOptions.middleware = [
createProxyMiddleware({
pathFilter: defaultSocketIoPath,
target: url.format({
protocol: 'http',
hostname: host,
port: bsPort,
pathname: path,
}),
ws: true,
logger: {
info: () => {},
warn: () => {},
error: () => {},
},
}),
];
}
}

Expand Down Expand Up @@ -376,27 +380,22 @@ function getSslConfig(
}

async function getProxyConfig(root: string, proxyConfig: string): Promise<MiddlewareHandler[]> {
const proxy = await loadProxyConfiguration(root, proxyConfig, false);
const createdProxies = [];
const { createProxyMiddleware } = await import('http-proxy-middleware');
for (const [key, context] of Object.entries(proxy)) {
if (typeof key === 'string') {
createdProxies.push(
createProxyMiddleware(
key.replace(/^\*$/, '**').replace(/\/\*$/, ''),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context as any,
) as MiddlewareHandler,
);
} else {
createdProxies.push(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createProxyMiddleware(key, context as any) as MiddlewareHandler,
);
}
const proxy = await loadProxyConfiguration(root, proxyConfig);
if (!proxy) {
return [];
}

return createdProxies;
const { createProxyMiddleware } = await import('http-proxy-middleware');

return Object.entries(proxy).map(([key, context]) => {
const filterRegExp = new RegExp(key);

return createProxyMiddleware({
pathFilter: (pathname) => filterRegExp.test(pathname),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(context as any),
});
});
}

export default createBuilder<SSRDevServerBuilderOptions, BuilderOutput>(execute);
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { loadEsmModule } from './load-esm';
export async function loadProxyConfiguration(
root: string,
proxyConfig: string | undefined,
normalize = false,
) {
): Promise<Record<string, object> | undefined> {
if (!proxyConfig) {
return undefined;
}
Expand Down Expand Up @@ -81,11 +80,7 @@ export async function loadProxyConfiguration(
}
}

if (normalize) {
proxyConfiguration = normalizeProxyConfiguration(proxyConfiguration);
}

return proxyConfiguration;
return normalizeProxyConfiguration(proxyConfiguration);
}

/**
Expand Down
16 changes: 14 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3700,7 +3700,7 @@
resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.4.tgz#7eb47726c391b7345a6ec35ad7f4de469cf5ba4f"
integrity sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==

"@types/http-proxy@^1.17.4", "@types/http-proxy@^1.17.8":
"@types/http-proxy@^1.17.10", "@types/http-proxy@^1.17.4", "@types/http-proxy@^1.17.8":
version "1.17.14"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.14.tgz#57f8ccaa1c1c3780644f8a94f9c6b5000b5e2eec"
integrity sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w==
Expand Down Expand Up @@ -8187,6 +8187,18 @@ [email protected], http-proxy-middleware@^2.0.3:
is-plain-obj "^3.0.0"
micromatch "^4.0.2"

[email protected]:
version "3.0.0"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-3.0.0.tgz#550790357d6f92a9b82ab2d63e07343a791cf26b"
integrity sha512-36AV1fIaI2cWRzHo+rbcxhe3M3jUDCNzc4D5zRl57sEWRAxdXYtw7FSQKYY6PDKssiAKjLYypbssHk+xs/kMXw==
dependencies:
"@types/http-proxy" "^1.17.10"
debug "^4.3.4"
http-proxy "^1.18.1"
is-glob "^4.0.1"
is-plain-obj "^3.0.0"
micromatch "^4.0.5"

http-proxy@^1.18.1:
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
Expand Down Expand Up @@ -9904,7 +9916,7 @@ methods@~1.1.2:
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==

micromatch@^4.0.2, micromatch@^4.0.4:
micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6"
integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==
Expand Down

0 comments on commit 733fba2

Please sign in to comment.