From fc71601074eaac3a5932928fe661d46f5c22ff65 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 24 Jan 2018 23:04:21 +0700 Subject: [PATCH] Updates * Show horizontal scrollbar for table only when needed. * Cache-Control for static files. --- lolisafe.js | 16 +++++++++++++--- package.json | 5 ++++- public/css/style.css | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lolisafe.js b/lolisafe.js index ef44c75..e373f09 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -32,11 +32,21 @@ safe.use('/api/register/', limiter) safe.use(bodyParser.urlencoded({ extended: true })) safe.use(bodyParser.json()) -if (config.serveFilesWithNode) { - safe.use('/', express.static(config.uploads.folder)) +const setHeaders = (res, path, stat) => { + if (/\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|js|css|eot|svg|ttf|woff|woff2)$/.test(path)) { + const day = 86400000 + res.set('Access-Control-Allow-Origin', '*') + res.append('Cache-Control', `must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800, max-age=${day * 30}`) // 30 days + } else { + res.append('Cache-Control', 'max-age=14400') // 4 hours + } } -safe.use('/', express.static('./public')) +if (config.serveFilesWithNode) { + safe.use('/', express.static(config.uploads.folder, { setHeaders })) +} + +safe.use('/', express.static('./public', { setHeaders })) safe.use('/', album) safe.use('/api', api) diff --git a/package.json b/package.json index 4e5a81d..f318486 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,9 @@ "standard": "^10.0.3" }, "standard": { - "envs": ["browser", "node"] + "envs": [ + "browser", + "node" + ] } } diff --git a/public/css/style.css b/public/css/style.css index a13b352..60ef10c 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -153,5 +153,5 @@ hr { } .table-container { - overflow-x: scroll; + overflow-x: auto; }