问题
I read this not very new post about disabling some things in sails.js. Specifically what I would like to try out is the disabling of etags.
Does anyone know how to disable that in sails.js (0.11.0)?
回答1:
You could disable it in the bootstap.js file:
// config/bootstrap.js
module.exports.bootstrap = function(cb) {
// Add this line to access to the Express app and disable etags
sails.hooks.http.app.disable('etag');
// It's very important to trigger this callback method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
cb();
};
回答2:
The above answer is only for dynamic files. For static files, you must override the www middleware by adding this code to the config/https.js file
www: (function() {
var flatFileMiddleware = require('serve-static')('.tmp/public', {
maxAge: 31557600000,
etag: false
});
return flatFileMiddleware;
})(),
The maxAge has to be there if you still want to set the cache-control header with an age. Also note that this will override the cache option in the same http.js file used to define that age.
For my purpose, I only wanted to remove the etags from the static files served up in the /min folder, which are the minified css and js files. So to do this I had to define a route in the routes.js file
'get /min/*': {
skipAssets: false,
fn: [
require('serve-static')('.tmp/public', {
maxAge: process.env.NODE_ENV !== 'production' ? 0 : 31557600000,
etag: false
}),
]
}
If you want more of the details, see here https://github.com/balderdashy/sails/issues/5306#issuecomment-508239510.
来源:https://stackoverflow.com/questions/32067991/sails-js-how-to-disable-etags