From 4acd93dae1dd1cad4770f6334681648a060d83cd Mon Sep 17 00:00:00 2001 From: Boris Bera Date: Wed, 1 Mar 2023 12:32:06 -0500 Subject: [PATCH] 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 --- .changeset/twenty-insects-live.md | 5 +++++ plugins/proxy-backend/src/service/router.ts | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 .changeset/twenty-insects-live.md diff --git a/.changeset/twenty-insects-live.md b/.changeset/twenty-insects-live.md new file mode 100644 index 0000000000..c20d3ee08d --- /dev/null +++ b/.changeset/twenty-insects-live.md @@ -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`. diff --git a/plugins/proxy-backend/src/service/router.ts b/plugins/proxy-backend/src/service/router.ts index b669e82f3f..3a646f2724 100644 --- a/plugins/proxy-backend/src/service/router.ts +++ b/plugins/proxy-backend/src/service/router.ts @@ -63,6 +63,12 @@ export interface ProxyConfig extends Options { reviveRequestBody?: boolean; } +function isValidHttpProxyMiddlewareLogLevel( + level: string, +): level is Exclude { + 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(