Converting my Express app to Koa...
I'm googling and I'm googling, I can't find how to pass extra params into Koa middleware. For example...
router.post('/', compose([
Midware.verifyAuthToken,
Midware.bodySchemaTest(UserController.bodyAttribs),
Midware.injectionTest
]), UserController.postNew);
I need send some variable bodyAttribs (string array) names into the bodySchemaTest middleware and I don't know how to do this in Koa.
I'm just now trying Koa. Please share your expertise :-)
Ok I worked it out myself. Not sure if this is smart or the "right" way to do this but the solution for me was to create a piece of middleware in each controller that sets expected schema attribs in ctx.state.bodyAttribs.
Like this...
So each controller provides the custom middleware that set the custom bodyAttribs I want to verify. You can use this approach to set and pass 1 to any number of extra params, whatever you need, in ctx.state which always goes on to next middleware in chain. Follow? :-)