Last active
May 21, 2016 00:44
-
-
Save mikermcneil/9cbd68c95839da480e97 to your computer and use it in GitHub Desktop.
From `sails.config.http` (http://sailsjs.org/#/documentation/reference/Configuration/sails.config.http.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
middleware: { | |
// Define a custom HTTP middleware fn with the key `foobar`: | |
foobar: function (req,res,next) { /*...*/ next(); }, | |
// Define another couple of custom HTTP middleware fns with keys `passportInit` and `passportSession` | |
// (notice that this time we're using an existing middleware library from npm) | |
passportInit : require('passport').initialize(), | |
passportSession : require('passport').session(), | |
// Override the conventional cookie parser: | |
cookieParser: function (req, res, next) { /*...*/ next(); } | |
} | |
// ... |
figured out like this.
hope this messsage will be helpful to someone else.
poweredBy: function(req, res, next) {
res.setHeader('X-Powered-By', "Autobots");
next();
},
compress: require('compression')(),
order: [
'startRequestTimer',
'cookieParser',
'session',
'myRequestLogger',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'router',
'www',
'favicon',
'404',
'500'
]
@calidion The problem of adding that in the http config, is that you will not have those headers when using sockets.
If you want to have them on sockets too, then, create a hook like this in /api/hooks/headers/index.js
/**
* Headers Hook that adds server name and powered by to request
* @param Object sails app
*/
module.exports = function (sails) {
return {
initialize: function (next) {
sails.emit('hook:headers:loaded');
return next();
},
routes: {
before: {
'all /*': function (req, res, next) {
res.setHeader('X-Served-By', require('os').hostname());
res.setHeader('X-Powered-By', 'SuperDupperApp');
return next();
}
}
}
};
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to enable compress and change poweredBy?