【发布时间】:2016-08-23 16:06:08
【问题描述】:
【问题讨论】:
标签: sails.js
【问题讨论】:
标签: sails.js
在将请求传递给控制器之前使用策略对请求进行预处理是非常好的。策略不仅仅用于身份验证和 acl。它们用途广泛,您可以将它们用于任何事情。
例如
policies/beforeUpdateTicket.js
module.exports = function(req, res, ok) {
TicketService.checkTicket(req.params.id, null, true).then(function(ticket) {
# You can even modify req.body
req.body.checked = true;
return ok();
}).fail(function(err) {
# Don't go to the controller, respond with error
return res.send(JSON.stringify({
message: 'some_error'
}), 409);
});
};
【讨论】: