mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 17:16:54 +00:00
update ttl, use file based hashing to prevent stale data.
This commit is contained in:
+19
-2
@@ -23,8 +23,25 @@ const server = http.createServer(app);
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
app.use(express.json());
|
||||
// Serve static files from the 'out' directory
|
||||
app.use(express.static(path.join(__dirname, "../../static")));
|
||||
app.use(
|
||||
express.static(path.join(__dirname, "../../static"), {
|
||||
maxAge: "1y", // Set max-age to 1 year for all static assets
|
||||
setHeaders: (res, path) => {
|
||||
// You can conditionally set different cache times based on file types
|
||||
if (path.endsWith(".html")) {
|
||||
// HTML files get shorter cache time
|
||||
res.setHeader("Cache-Control", "public, max-age=60");
|
||||
} else if (path.match(/\.(js|css|svg)$/)) {
|
||||
// JS, CSS, SVG get long cache with immutable
|
||||
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
||||
} else if (path.match(/\.(bin|dat|exe|dll|so|dylib)$/)) {
|
||||
// Binary files also get long cache with immutable
|
||||
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
||||
}
|
||||
// Other file types use the default maxAge setting
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.use(express.json());
|
||||
|
||||
app.set("trust proxy", 3);
|
||||
|
||||
Reference in New Issue
Block a user