如何使用 FeathersJs 在钩子中设置和访问内部服务

How to setup and access internal services in hooks using FeathersJs

我想在添加到 public REST 端点的挂钩中使用内部定义的服务,这可能吗?

根据内部定义,我指的是使用 feathers-common-hooks 中的 disallow 钩子。

app.service('/api/internal/helper').hooks( { before: { all: disallow('rest') } } )

钩子查看 context 对象中的 provider,如果它与我禁用的匹配。即如果使用 disallow('rest') 则它会禁止从 REST 访问服务。

问题是我想在附加到 public 服务的挂钩中使用这个内部 helper 服务,但还没有找到这样做的方法。当调用内部服务时 provider 仍然是 rest 并且调用被阻止。

这些钩子的作用是寻找 params.provider being set. Anything where params.provider is not set is considered an internal call. If you want to pass other params along to the internal call you can e.g. _.omit provider 属性:

app.service('/api/internal/helper').find(omit(context.params, 'provider'))