How to use custom route middleware with Sails.js? (ExpressJS)

后端 未结 3 1691
独厮守ぢ
独厮守ぢ 2021-01-12 01:15

I\'ve just unpacked a fresh copy of the Node framework Sails.js. It is built on Express 3. In the /config/routes.js file is this comment:

/**
 * (1) Core m         


        
3条回答
  •  自闭症患者
    2021-01-12 01:32

    I had the same issue of figuring out how to make use of middlewares. They are basically defined in the config/policies.js.
    So, if you want to use middlewares(aka policies) like old style, you can do the following (this may not be the nicest way):

    // config/policies.js
    '*': [ 
      express.logger(),
      function(req, res, next) {
        // do whatever you want to
        // and then call next()
        next();
      }
    ]
    

    However, the real sailjs way is to put all such policies in api/policies/ folder

提交回复
热议问题