Pass logLevel to http-proxy-middleware

Under the hood, `http-proxy-middleware` checks its log level to see if
it should log requests. Passing in the log level ensures that we see
those messages when we run with `LOG_LEVEL=debug`.

Signed-off-by: Boris Bera <bbera@coveo.com>
This commit is contained in:
Boris Bera
2023-03-01 12:32:06 -05:00
parent f758b99ea2
commit 4acd93dae1
2 changed files with 14 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-proxy-backend': patch
---
Pass the current log level to `http-proxy-middleware` to ensure that proxies requests are shown when log level is set to `debug`.
@@ -63,6 +63,12 @@ export interface ProxyConfig extends Options {
reviveRequestBody?: boolean;
}
function isValidHttpProxyMiddlewareLogLevel(
level: string,
): level is Exclude<Options['logLevel'], undefined> {
return ['debug', 'info', 'warn', 'error', 'silent'].includes(level);
}
// Creates a proxy middleware, possibly with defaults added on top of the
// given config.
export function buildMiddleware(
@@ -121,6 +127,9 @@ export function buildMiddleware(
// Attach the logger to the proxy config
fullConfig.logProvider = () => logger;
if (isValidHttpProxyMiddlewareLogLevel(logger.level)) {
fullConfig.logLevel = logger.level;
}
// Only return the allowed HTTP headers to not forward unwanted secret headers
const requestHeaderAllowList = new Set<string>(