我在 Sails js 中编写了基本策略。
在 app/config/policies.js
module.exports.policies = {
'*': 'sessionAuth'
};
在 app/api/policies/sessionAuth.js
module.exports = function(req, res, next) {
console.log('reach');
if (req.session.authenticated) {
return next();
}
return res.forbidden('You are not permitted to perform this action.');
};
但是当我请求一些 URL 时,'reach' 没有在控制台中打印,并且这个基本策略不起作用。它将执行在 route.js 中定义的控制器操作。