server_photo_s85js/middleware/static.js
2026-08-11 08:45:04 +02: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'
);
}
}
});