2
我通過遠程鉤documentation去了,我可以成功地創建遠程掛鉤無需額外參數的方法,如login
, 是:如何編寫遠程鉤與參數和關係的方法
customer.afterRemote('login', function(ctx, modelInstance, next) {
if (ctx.result) {
...
next();
}
else{
next();
}
});
現在如何寫遠程掛鉤的方法說:
GET /customers/{id}
POST /customers/{id}
或 同時發佈相關的對象,如
POST /customers/{id}/contacts
GET /customers/{id}/contacts
我知道這樣與POST /customers/{id}/contacts
如下:
customer.beforeRemote('**', function(ctx, user, next) {
console.log(ctx.methodString, 'was invoked remotely'); // customers.prototype.save was invoked remotely
next();
});
將返回該方法被稱爲一個喜歡的名字:
customer.prototype .__ create__contacts被遠程調用
但我仍然無法明確地勾住它,並且下面的嘗試是無濟於事,並且鉤子沒有被達到:
customer.beforeRemote('customer.prototype.__create__contacts', function(ctx, user, next)
customer.beforeRemote(customer.prototype.__create__contacts, function(ctx, user, next)