From 6800d005a1a4414ae064d883db1e45eef780c058 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Fri, 26 Jun 2026 16:55:11 +0200 Subject: [PATCH] Added feature to enable/disable Web UI microservice HTTP response compression (#15836) * Added feature to enable/disable Web UI microservice HTTP response compression * Minor code style improvement --- msa/web-ui/config/custom-environment-variables.yml | 4 ++++ msa/web-ui/config/default.yml | 4 ++++ msa/web-ui/server.ts | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/msa/web-ui/config/custom-environment-variables.yml b/msa/web-ui/config/custom-environment-variables.yml index 6ba9147555..5430bb4c4e 100644 --- a/msa/web-ui/config/custom-environment-variables.yml +++ b/msa/web-ui/config/custom-environment-variables.yml @@ -19,6 +19,10 @@ server: address: "HTTP_BIND_ADDRESS" # Server bind port port: "HTTP_BIND_PORT" + # HTTP response compression + compression: + # Enable/disable HTTP response compression + enabled: "HTTP_COMPRESSION_ENABLED" thingsboard: enableProxy: "TB_ENABLE_PROXY" # ThingsBoard node host diff --git a/msa/web-ui/config/default.yml b/msa/web-ui/config/default.yml index 6ffa85b3bc..7911a35bb5 100644 --- a/msa/web-ui/config/default.yml +++ b/msa/web-ui/config/default.yml @@ -19,6 +19,10 @@ server: address: "0.0.0.0" # Server bind port port: "8090" + # HTTP response compression + compression: + # Enable/disable HTTP response compression + enabled: "true" thingsboard: enableProxy: "false" # ThingsBoard node host diff --git a/msa/web-ui/server.ts b/msa/web-ui/server.ts index 0a4ddbfa6b..84f4ed8f70 100644 --- a/msa/web-ui/server.ts +++ b/msa/web-ui/server.ts @@ -82,6 +82,9 @@ let connections: Socket[] = []; } logger.info('Security headers: %s', JSON.stringify(securityHeaders)); + const compressionEnabled = isEnabled(config.get('server.compression.enabled')); + logger.info('HTTP response compression enabled: %s', compressionEnabled); + // Apply security headers to all responses app.use((_req, res, next) => { for (const [name, value] of Object.entries(securityHeaders)) { @@ -126,7 +129,9 @@ let connections: Socket[] = []; } app.use(historyApiFallback()); - app.use(compression()); + if (compressionEnabled) { + app.use(compression()); + } const root = path.join(webDir, 'public');