Browse Source
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
pull/15856/head
Maksym Tsymbarov
5 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
14 additions and
1 deletions
-
msa/web-ui/config/custom-environment-variables.yml
-
msa/web-ui/config/default.yml
-
msa/web-ui/server.ts
|
|
|
@ -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 |
|
|
|
|
|
|
|
@ -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 |
|
|
|
|
|
|
|
@ -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'); |
|
|
|
|
|
|
|
|