taisai-svelte/preview-gzip.js

34 lines
810 B
JavaScript

import express from 'express';
import expressStaticGzip from 'express-static-gzip';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const port = 4173;
// gzip 압축 파일을 우선적으로 제공
app.use(
'/',
expressStaticGzip(join(__dirname, '.svelte-kit/output/client'), {
enableBrotli: false,
orderPreference: ['gz'],
serveStatic: {
maxAge: '1d',
setHeaders: (res, path) => {
if (path.endsWith('.html')) {
res.setHeader('Cache-Control', 'public, max-age=0');
}
}
}
})
);
app.listen(port, () => {
console.log(`\n ➜ Preview server with gzip: http://localhost:${port}/`);
console.log(` ➜ Press Ctrl+C to stop\n`);
});