Loopbackjs 带有通配符的RemoteHooks不';不要在储存容器中工作

Loopbackjs 带有通配符的RemoteHooks不';不要在储存容器中工作,loopbackjs,strongloop,Loopbackjs,Strongloop,我使用的文件上传,它的作品很好。 我想对上传的文件进行后处理,所以我添加了远程钩子方法beforemote和afterRemote。当我使用'*'作为方法名时,它就起作用了。当我将其更改为'upload'或'container.upload'或任何其他内容时,它将停止工作。 即使是afterSave也不为容器调用 module.exports = function(Container) { Container.beforeRemote('*.upload', function(ctx, un

我使用的文件上传,它的作品很好。 我想对上传的文件进行后处理,所以我添加了远程钩子方法beforemoteafterRemote。当我使用'*'作为方法名时,它就起作用了。当我将其更改为'upload''container.upload'或任何其他内容时,它将停止工作。 即使是afterSave也不为容器调用

module.exports = function(Container) {

 Container.beforeRemote('*.upload', function(ctx, unused, next) {
  if(ctx.req.accessToken) {
     console.log('beforeCalled with token');
   next();
  } else {
    console.log('beforeCalled no token');
    next();
  }
 });

 Container.afterRemote('*.upload', function(ctx, user, next) {
   console.log("file uploaded", user.result.files);
   next();
  });

 Container.beforeSave = function(next, modelInstance) {
  console.log("beforeSave:", modelInstance );
  next();
 };

};

我错过什么了吗?应该如何做?

对于这种特殊情况,可以选择
容器。beforeRemote('**.upload',函数(ctx,未使用,下一个)
容器。beforeRemote('upload',函数(ctx,未使用,下一个)
应该可以正常工作。最好能从环回开发人员那里得到反馈,但正确的方法是什么。

您现在可以使用以下方法解决此问题:

Container.beforeRemote('**', function(ctx, unused, next) {
  if(ctx.methodString === ‘upload’) {
    ...
  }
}

请参见

不幸的是,它不起作用,只适用于
“*”
您有哪个版本的环回?我刚刚测试了这两个版本,它们适用于我。strongloop v2.9.2(节点v0.10.33),奇怪的是它对你有效…因为我在调试它,我发现在afterRemote处理中,remotes.container.\u方法是空的…Update#1
container.afterRemote('upload'),…
将立即工作Update#2 for
container.afterRemote('**',…
,条件比较字符串是
container.upload
,而不是
upload