node.js - Keystone 无法隐藏 x-powered-by

标签 node.js express keystonejs

我尝试使用expressjs命令删除node.js和express x-powered-by,但它们不起作用。

以下是我在处理其他项目时使用的命令

app.disable('x-powered-by');

app.set('x-powered-by', false);

在 keystonejs 中还有其他方法可以做到这一点吗?

最佳答案

我已经找到了解决这个问题的方法 您必须在路由 - 中间件上使用它,而不是在 keystone.js 中使用它

var keystone = require('keystone');
var middleware = require('./middleware');
var importRoutes = keystone.importer(__dirname);

// Common Middleware
keystone.pre('routes', middleware.initLocals);
keystone.pre('render', middleware.flashMessages);

// Import Route Controllers
var routes = {
    views: importRoutes('./views'),
};

// Setup Route Bindings
exports = module.exports = function (app) {
    // Views
    app.set('x-powered-by', false);//<<< Place it here
    app.get('/', routes.views.news);
};

关于node.js - Keystone 无法隐藏 x-powered-by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42063022/

相关文章:

javascript - 刷新后express-flash消息为空

node.js - 如何修复 : 'MongoError: authentication fail' @MongoDB Atlas

node.js - ExpressJs 与 NodeJs 版本的兼容性

javascript - Raven 不使用 Sentry 中的源映射来处理 TS/JS 代码

node.js - 如何: Execute infinite scroll using AngularJS and change route on every new post

mysql - 从 sequelize 查询返回一个值

mysql - 使用 Express 将多个 SQL 结果返回到 .handlebars

node.js - 带有标题的图片库,在 keystonejs 上使用 CloudinaryImage

javascript - Keystonejs:自定义名称到管理 UI 的默认列

javascript - Kik 卡 - 我可以导入/需要 Kik.js 文件吗?