插座具有以下策略:政策在Sails.js
// file: api/policies/foo.js
module.exports = function(req, res, next) {
Model.find().done(function(err, result) {
if (result.length > 5) {
return res.forbidden();
} else {
return next();
}
});
};
// file: config/policies.js
module.exports.policies = {
ModelController: {
'find': 'foo'
}
};
和默認Model
和ModelController
。我現在表演上兩個客戶端執行以下操作:
// client 1
socket.get('/model', function(result) { console.log(result) });
// client 2
var i = 10;
while (i--) { socket.post('/model', { foo: 'bar' }); }
客戶端1實際接收10次更新,雖然他只允許接收5 當通過socket.get
重新連接,我得到一個適當的權限錯誤。
我的問題: 在通過套接字發送更新之前檢查權限的最佳做法是什麼?
直視前進 - 謝謝! – pex