Skip to content

Commit

Permalink
Merge pull request #6688 from rancher-sandbox/dependabot/npm_and_yarn…
Browse files Browse the repository at this point in the history
…/http-proxy-middleware-3.0.0

Bump http-proxy-middleware from 2.0.6 to 3.0.0
  • Loading branch information
Nino-K authored Apr 11, 2024
2 parents c6ad398 + 624e1e4 commit 3774425
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"express": "4.18.2",
"fs-extra": "11.2.0",
"http-proxy-agent": "7.0.2",
"http-proxy-middleware": "2.0.6",
"http-proxy-middleware": "3.0.0",
"https-proxy-agent": "7.0.2",
"intl-messageformat": "10.5.8",
"jquery": "3.7.1",
Expand Down
2 changes: 1 addition & 1 deletion pkg/rancher-desktop/assets/styles/base/_functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$color-brightness: brightness($color);
$dark-text-brightness: brightness($dark);
$light-text-brightness: brightness($light);
@return if(abs($color-brightness - $light-text-brightness) > abs($color-brightness - $dark-text-brightness), $light, $dark);
@return if(math.abs($color-brightness - $light-text-brightness) > math.abs($color-brightness - $dark-text-brightness), $light, $dark);
}
}

Expand Down
27 changes: 14 additions & 13 deletions pkg/rancher-desktop/main/dashboardServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
import express from 'express';
import { createProxyMiddleware, Options, RequestHandler } from 'http-proxy-middleware';

import { proxyWsOpts, proxyOpts, proxyMetaOpts } from './proxyUtils';
import { proxyWsOpts, proxyOpts } from './proxyUtils';

import Logging from '@pkg/utils/logging';
import paths from '@pkg/utils/paths';
Expand All @@ -30,20 +30,21 @@ export class DashboardServer {

private proxies = (() => {
const proxy: Record<ProxyKeys, Options> = {
'/k8s': proxyWsOpts(this.api), // Straight to a remote cluster (/k8s/clusters/<id>/)
'/pp': proxyWsOpts(this.api), // For (epinio) standalone API
'/api': proxyWsOpts(this.api), // Management k8s API
'/apis': proxyWsOpts(this.api), // Management k8s API
'/v1': proxyWsOpts(this.api), // Management Steve API
'/v3': proxyWsOpts(this.api), // Rancher API
'/v3-public': proxyOpts(this.api), // Rancher Unauthed API
'/api-ui': proxyOpts(this.api), // Browser API UI
'/meta': proxyMetaOpts(this.api), // Browser API UI
'/v1-*': proxyOpts(this.api), // SAML, KDM, etc
'/k8s': proxyWsOpts(), // Straight to a remote cluster (/k8s/clusters/<id>/)
'/pp': proxyWsOpts(), // For (epinio) standalone API
'/api': proxyWsOpts(), // Management k8s API
'/apis': proxyWsOpts(), // Management k8s API
'/v1': proxyWsOpts(), // Management Steve API
'/v3': proxyWsOpts(), // Rancher API
'/api-ui': proxyOpts(), // Browser API UI
'/v3-public': proxyOpts(), // Rancher Unauthed API
'/meta': proxyOpts(), // Browser API UI
'/v1-*': proxyOpts(), // SAML, KDM, etc
};

return Object.fromEntries(Object.entries(proxy)
.map(([key, options]) => [key, createProxyMiddleware(options)])) as unknown as Record<ProxyKeys, RequestHandler>;
return Object.fromEntries(Object.entries(proxy).map(([key, options]) => {
return [key, createProxyMiddleware({ ...options, target: this.api + key })];
})) as unknown as Record<ProxyKeys, RequestHandler>;
})();

/**
Expand Down
21 changes: 9 additions & 12 deletions pkg/rancher-desktop/main/dashboardServer/proxyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@ import { Options } from 'http-proxy-middleware';
import Logging from '@pkg/utils/logging';

const console = Logging.dashboardServer;
const logProvider = () => console;

export const proxyOpts = (target: string): Options => {
export const proxyOpts = (): Omit<Options, 'target'> => {
return {
target,
followRedirects: true,
secure: false,
logLevel: 'info',
logProvider,
onProxyReq,
onProxyReqWs,
onError,
logger: console,
on: {
proxyReq: onProxyReq,
proxyReqWs: onProxyReqWs,
error: onError,
},
};
};

export const proxyWsOpts = (target: string): Options => {
export const proxyWsOpts = (): Omit<Options, 'target'> => {
return {
...proxyOpts(target),
...proxyOpts(),
ws: false,
changeOrigin: true,
};
};

export const proxyMetaOpts = (target: string): Options => proxyOpts(target);

const onProxyReq = (proxyReq: any, req: any) => {
if (!(proxyReq._currentRequest && proxyReq._currentRequest._headerSent)) {
proxyReq.setHeader('x-api-host', req.headers['host']);
Expand Down
24 changes: 18 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2728,10 +2728,10 @@
resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.1.tgz#20172f9578b225f6c7da63446f56d4ce108d5a65"
integrity sha512-/K3ds8TRAfBvi5vfjuz8y6+GiAYBZ0x4tXv1Av6CWBWn0IlADc+ZX9pMq7oU0fNQPnBwIZl3rmeLp6SBApbxSQ==

"@types/http-proxy@^1.17.8":
version "1.17.11"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.11.tgz#0ca21949a5588d55ac2b659b69035c84bd5da293"
integrity sha512-HC8G7c1WmaF2ekqpnFq626xd3Zz0uvaqFmBJNRZCGEZCXkvSdJoNFn/8Ygbd9fKNQj8UzLdCETaI0UWPAjK7IA==
"@types/http-proxy@^1.17.10", "@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==
dependencies:
"@types/node" "*"

Expand Down Expand Up @@ -7799,7 +7799,19 @@ http-proxy-agent@^5.0.0:
agent-base "6"
debug "4"

http-proxy-middleware@2.0.6, http-proxy-middleware@^2.0.3:
http-proxy-middleware@3.0.0:
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-middleware@^2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz#e1a4dd6979572c7ab5a4e4b55095d1f32a74963f"
integrity sha512-ya/UeJ6HVBYxrgYotAZo1KvPWlgB48kUJLDePFeneHsVujFaW5WNj2NgWCAE//B1Dl02BIfYlpNgBy8Kf8Rjmw==
Expand Down Expand Up @@ -9885,7 +9897,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.0, micromatch@^4.0.2, micromatch@^4.0.4:
micromatch@^4.0.0, 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 3774425

Please sign in to comment.