moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 118 forks source link

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

Open XHMM opened 3 years ago

XHMM commented 3 years ago

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.

icebob commented 3 years ago

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.

XHMM commented 3 years ago

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?

icebob commented 3 years ago

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