Register a middleware for specific service in V5 #3178
Replies: 4 comments 2 replies
-
Whoops I forgot to add this to the docs (now documented here. It is possible to pass a app.use('/todos', new TodoService(), {
koa: {
before: [
async (ctx, next) => {
ctx.feathers // data that will be merged into sevice `params`
// This will run all subsequent middleware and the service call
await next()
// Then we have additional properties available on the context
ctx.hook // the hook context from the method call
ctx.body // the return value
}
]
}
}) |
Beta Was this translation helpful? Give feedback.
-
can i register an after service middleware as well? |
Beta Was this translation helpful? Give feedback.
-
A Koa middleware does both, before and after. You can do things before and after |
Beta Was this translation helpful? Give feedback.
-
I want to do it with a service object Is this syntax valid ? async function redirect(ctx, next){} app.use(path, new service(), {koa:{after:[redirect]}}) Edit : |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How can I register a middleware for specific service like with v4.
I want to reproduce this with koa in V5, ie register a middleware before and after a specific service not globally like explain in documentation.
Beta Was this translation helpful? Give feedback.
All reactions