summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-12-28 16:29:37 +0100
committerTor Andersson <tor@ccxvii.net>2021-12-29 17:02:47 +0100
commit0a8a73c47d8fe0c63425af3ab0394ae52b0f3532 (patch)
treed467109950b7f75ceffafcf8c5fc2277e30b1605 /server.js
parent099bc0fc03182e291cf930c7e6d441502934f9b5 (diff)
downloadserver-0a8a73c47d8fe0c63425af3ab0394ae52b0f3532.tar.gz
Only set cache-control max-age on images and web fonts.
Diffstat (limited to 'server.js')
-rw-r--r--server.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/server.js b/server.js
index 8d4c24b..50fa751 100644
--- a/server.js
+++ b/server.js
@@ -79,12 +79,19 @@ function login_delete(res, sid) {
* Web server setup.
*/
+function set_static_headers(res, path) {
+ if (path.match(/\.(jpg|png|svg|webp|ico|woff2)/))
+ res.setHeader('Cache-Control', 'max-age=86400');
+ else
+ res.setHeader('Cache-Control', 'max-age=0');
+}
+
let app = express();
app.set('x-powered-by', false);
app.set('etag', false);
app.set('view engine', 'pug');
app.use(compression());
-app.use(express.static('public', { etag: false, maxAge: 24*3600*1000 }));
+app.use(express.static('public', { etag: false, cacheControl: false, setHeaders: set_static_headers }));
app.use(express.urlencoded({extended:false}));
let http_port = process.env.HTTP_PORT || 8080;