Reputation: 2397
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.
Upvotes: 2
Views: 470
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