Gayan Hewa
Gayan Hewa

Reputation: 2397

sailsjs v0.11 and express-validator

I have had some issues setting up SailsJS to use the express-validator middleware.

I ended up using the a custom middleware to get it to work :

  customMiddleware: function(app){
    var v= require('express-validator');
    app.use(v());
  } 

Any advise on getting this to work with the accepted method of using 3rd party middleware would be appreciated. I have gone trough a couple of questions , forum posts plus the documentation but the above method was the only way I could get this to work so I can continue the development.

  1. http://sailsjs.org/#!/documentation/concepts/Middleware

  2. https://github.com/ctavan/express-validator

Upvotes: 2

Views: 470

Answers (1)

Matt Wielbut
Matt Wielbut

Reputation: 2692

I had no problems getting the following to work without needing to use the "customMiddleware" function. I believe this is the recommended approach.

In config/http.js, note the added expressValidator property and the 'expressValidator' entry in the order[] stack JUST BEFORE the 'bodyParser'.

order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'expressValidator',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      'poweredBy',
      '$custom',
      'router',
      'www',
      //'favicon',
      '404',
      '500'
],

expressValidator: require('express-validator')()

Upvotes: 1

Related Questions