Search code examples
node.jsexpresskeystonejs

Keystone cant hide x-powered-by


I'm trying to remove both node.js and express x-powered-by with expressjs commands but they don't work.

Here are the commands that I'm using both where working on other projects

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

or

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

Is there another way to do this in keystonejs?


Solution

  • Well i have found a solution to this Instead of using it at the keystone.js you must use it on the routes - middleware

    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);
    };