fix: reativa gzip no Express com threshold de 1KB
Caddy/Traefik não estavam comprimindo os assets. Reativando gzip no Express com threshold de 1KB para garantir compressão de todos os arquivos JS/CSS.
This commit is contained in:
parent
cfb60b2d4b
commit
58efb8c95c
|
|
@ -1,6 +1,7 @@
|
|||
import express, { type Express } from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import compression from "compression";
|
||||
|
||||
export function serveStatic(app: Express) {
|
||||
const distPath = path.resolve(__dirname, "public");
|
||||
|
|
@ -10,13 +11,33 @@ export function serveStatic(app: Express) {
|
|||
);
|
||||
}
|
||||
|
||||
// NOTA: Gzip é gerenciado pelo Traefik (coolify-proxy)
|
||||
// Não usar middleware compression aqui para evitar conflito
|
||||
// O Traefik já tem: traefik.http.middlewares.gzip.compress=true
|
||||
// Enable gzip compression for static assets
|
||||
// Caddy/Traefik devem respeitar isso ou fazer override
|
||||
app.use(compression({
|
||||
level: 6,
|
||||
threshold: 1024, // Compress files > 1KB
|
||||
filter: (req, res) => {
|
||||
// Don't compress if already compressed by proxy
|
||||
if (req.headers['x-no-compression']) {
|
||||
return false;
|
||||
}
|
||||
// Compress JS, CSS, JSON, HTML
|
||||
const contentType = res.getHeader('content-type') || '';
|
||||
if (typeof contentType === 'string') {
|
||||
if (contentType.includes('javascript') ||
|
||||
contentType.includes('css') ||
|
||||
contentType.includes('json') ||
|
||||
contentType.includes('html')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return compression.filter(req, res);
|
||||
},
|
||||
}));
|
||||
|
||||
// Serve static files with proper caching
|
||||
app.use(express.static(distPath, {
|
||||
maxAge: '1y', // Cache static assets for 1 year (they have hash in filename)
|
||||
maxAge: '1y',
|
||||
etag: true,
|
||||
lastModified: true,
|
||||
}));
|
||||
|
|
|
|||
Loading…
Reference in New Issue