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

后端 未结 3 1694
独厮守ぢ
独厮守ぢ 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:47

    You can use policies to achieve this. Save your isAjax function as isAjax.js under your api/policies folder, and change it to just use module.exports instead of module.exports.isAjax. Then in your config/policies.js file, you can specify which controllers/actions to apply the policy to--to run isAjax for every route, just do:

    '*':'isAjax'
    

    in that file.

提交回复
热议问题