How to get Props in Middleware


#1

Hi)

For example, I have route with middleware with passed props:

Route
  .post('posts', 'PostController.show')
  .middleware(['process:type'])

How can I get this props inside ‘process’ middleware?


#2

When writing middleware, you can pass 3 things to handle:

async handle(ctx, next, schemes) {

You are interested in third one.

In your case, schemes param will be equal to array: ['type']. You can pass multiple params to middleware schemes by using comma like: .middleware(['process:type,something']) will give you schemes array inside middleware that equals: ['type', 'something']


#3

oh, thanks!) I’ll make PR for docs)