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');