From a4dcd007e4ffa21cf88db01241930fb3ee79532a Mon Sep 17 00:00:00 2001 From: Boris Bera Date: Tue, 7 Mar 2023 12:04:57 -0500 Subject: [PATCH] Pass `debug` log level to http-proxy-middleware Signed-off-by: Boris Bera --- .changeset/twenty-insects-live.md | 2 +- plugins/proxy-backend/src/service/router.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.changeset/twenty-insects-live.md b/.changeset/twenty-insects-live.md index c20d3ee08d..d3f8cdfc25 100644 --- a/.changeset/twenty-insects-live.md +++ b/.changeset/twenty-insects-live.md @@ -2,4 +2,4 @@ '@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`. +Ensure that `@backstage/plugin-proxy-backend` logs the requests that it proxies 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 3a646f2724..6912965659 100644 --- a/plugins/proxy-backend/src/service/router.ts +++ b/plugins/proxy-backend/src/service/router.ts @@ -63,12 +63,6 @@ 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( @@ -127,9 +121,11 @@ export function buildMiddleware( // Attach the logger to the proxy config fullConfig.logProvider = () => logger; - if (isValidHttpProxyMiddlewareLogLevel(logger.level)) { - fullConfig.logLevel = logger.level; - } + // http-proxy-middleware uses this log level to check if it should log the + // requests that it proxies. Setting this to the most verbose log level + // ensures that it always logs these requests. Our logger ends up deciding + // if the logs are displayed or not. + fullConfig.logLevel = 'debug'; // Only return the allowed HTTP headers to not forward unwanted secret headers const requestHeaderAllowList = new Set(