Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ...
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(); }
}
// ...
@calidion

This comment has been minimized.

Copy link

@calidion calidion commented Sep 17, 2014

how to enable compress and change poweredBy?

@calidion

This comment has been minimized.

Copy link

@calidion calidion commented Sep 17, 2014

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'
    ]
@luislobo

This comment has been minimized.

Copy link

@luislobo luislobo commented May 21, 2016

@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
You can’t perform that action at this time.