Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use express-validator as a middleware with websockets

I used Sails.js + Passport.js authentication through websockets to bind passport.js methods for requests through websockets (using sockets.io) , but how should i add express-validator methods to ensure that all requests have methods from it

like image 774
kobe24 Avatar asked Jul 17 '18 08:07

kobe24


1 Answers

You can do it without using customMiddleware by adding 'express-validator' in the config/http.js:

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

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

This should get you express validator and you can import and use it.

Hope it solves your query.

like image 154
Harshal Y. Avatar answered Oct 02 '22 12:10

Harshal Y.