moleculer-web icon indicating copy to clipboard operation
moleculer-web copied to clipboard

update request body or query in alias-level middleware not work

Open XHMM opened this issue 4 years ago • 3 comments

When route-level middleware changed request body or query, action can get changed data, but if alias-level middleware changed it, it not work.

Here is a reproduce demo: after run npm run dev, then run curl -X POST localhost:8080/test, you can find the (maybe) bug.

XHMM avatar Dec 25 '20 19:12 XHMM

The reason is that the "query", "body" and "params" are processed after route middleware. So before action middlewares called, they are merged into req.$params, so you can modify through it, it will be the ctx.params.

icebob avatar Dec 27 '20 21:12 icebob

Thanks for reply, with the help of view source code, I understood the internal.

I think the document description is not clear, which can make people mistakenly think that the use of the two middleware is the same, maybe should point out the difference?

XHMM avatar Dec 29 '20 02:12 XHMM

Yeah, maybe the documentation needs some improvements to this topic.

icebob avatar Dec 31 '20 10:12 icebob