gallery_server_client_s190js/middleware/static.js
2026-10-26 11:00:14 +01:00

28 lines
647 B
JavaScript

const express = require('express');
const path = require('path');
const PUBLIC_ROOT = path.join(__dirname, '..', 'public');
module.exports = express.static(PUBLIC_ROOT, {
etag: true,
lastModified: true,
cacheControl: true,
setHeaders(res, filePath) {
const normalizedPath = filePath
.replaceAll('\\', '/')
.toLowerCase();
const isThumbnail =
normalizedPath.includes('/photos/') &&
normalizedPath.includes('/thumbs/') &&
/\.(jpg|jpeg|png|webp|gif)$/i.test(normalizedPath);
if (isThumbnail) {
res.setHeader(
'Cache-Control',
'public, max-age=86400'
);
}
}
});