简体   繁体   中英

How to setup and access internal services in hooks using FeathersJs

I want to use internally defined services in hooks added to public REST endpoints, is this possible?

By internally defined I'm referring to using the disallow hook from feathers-common-hooks.

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

The hook looks at the provider in the context object, if it matches what I've disabled. Ie if disallow('rest') is used then it disables the service from being accessed from REST.

The problem is I want to use this internal helper service in a hook that is attached to a public service, but haven't found a way to do so. When the internal service is called the provider is still rest and the call is blocked.

What those hooks do is look for 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 eg _.omit the provider property:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM