In middleware, this == ctx, but could not get params object.
// app/middleware/uppercase.js
module.exports = () => {
// url == /api/user/:id
return function* (next) {
const id = this.params || this.req.params; // undefined
yield next;
};
};
this.ctx.req.params ?
param is a feature of router, so you can't got it before router
发自我的 iPhone
在 2017年8月25日,11:38,Ryan notifications@github.com 写道:
this.req.params ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@atian25 Can i put my middleware behind the router?
I need do some url params or query params check in middleware.
you can got query in any middleware, except param which extract from url path.
发自我的 iPhone
在 2017年8月25日,11:58,流星狂飙 notifications@github.com 写道:
@atian25 Can i put my middleware behind the router?
I need do some url params or query params check in middleware.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Add middleware after router, then you can the this.params.
// app/router.js
const uppercase = app.middlewares.uppercase();
app.get('/api/user/:id', uppercase, 'your controller here');
Awesome!!
@fengmk2 same as get params in working url...
Most helpful comment
Add middleware after router, then you can the
this.params.