我读到这并不是很新的帖子关于禁用sails.js中的一些东西的文章。具体来说,我想尝试的是禁用etags。
有人知道如何在sails.js (0.11.0)中禁用它吗?
发布于 2015-08-19 12:49:52
您可以在文件中禁用它
// 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();
};发布于 2019-07-03 21:04:40
以上答案仅适用于动态文件。对于静态文件,必须将此代码添加到config/https.js文件中,从而覆盖www中间件。
www: (function() {
var flatFileMiddleware = require('serve-static')('.tmp/public', {
maxAge: 31557600000,
etag: false
});
return flatFileMiddleware;
})(),如果仍然希望设置具有年龄的缓存控制报头,则必须使用maxAge。还请注意,这将覆盖用于定义该年龄的同一个http.js文件中的缓存选项。
出于我的目的,我只想从/min文件夹中提供的静态文件中删除etags,这些文件是精简的css和js文件。为此,我必须在routes.js文件中定义一个路由
'get /min/*': {
skipAssets: false,
fn: [
require('serve-static')('.tmp/public', {
maxAge: process.env.NODE_ENV !== 'production' ? 0 : 31557600000,
etag: false
}),
]
}如果您想了解更多细节,请参见这里的https://github.com/balderdashy/sails/issues/5306#issuecomment-508239510。
https://stackoverflow.com/questions/32067991
复制相似问题