fix: Improve browser caching for public files
This commit is contained in:
@@ -9,6 +9,9 @@
|
|||||||
* https://sailsjs.com/config/http
|
* https://sailsjs.com/config/http
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const serveStatic = require('serve-static');
|
||||||
|
const sails = require('sails');
|
||||||
|
|
||||||
module.exports.http = {
|
module.exports.http = {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -50,5 +53,14 @@ module.exports.http = {
|
|||||||
// })(),
|
// })(),
|
||||||
|
|
||||||
poweredBy: false,
|
poweredBy: false,
|
||||||
|
|
||||||
|
www(req, res, next) {
|
||||||
|
const middleware = serveStatic(sails.config.paths.public, {
|
||||||
|
maxAge: sails.config.http.cache,
|
||||||
|
immutable: req.url.startsWith('/assets/'),
|
||||||
|
});
|
||||||
|
|
||||||
|
return middleware(req, res, next);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,7 +47,11 @@ function staticDirServer(prefix, dirFn) {
|
|||||||
// Custom config properties are not available when the routes config is
|
// Custom config properties are not available when the routes config is
|
||||||
// loaded, so resolve the target value just before serving the request.
|
// loaded, so resolve the target value just before serving the request.
|
||||||
const dir = dirFn();
|
const dir = dirFn();
|
||||||
const staticServer = serveStatic(dir, { index: false });
|
const staticServer = serveStatic(dir, {
|
||||||
|
index: false,
|
||||||
|
maxAge: sails.config.http.cache,
|
||||||
|
immutable: true,
|
||||||
|
});
|
||||||
|
|
||||||
const reqPath = req.url;
|
const reqPath = req.url;
|
||||||
if (reqPath.startsWith(prefix)) {
|
if (reqPath.startsWith(prefix)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user