boardgame.io
boardgame.io copied to clipboard
Adding middleware causes crash
Trying to add a middleware that reads the number of players and getting a crash saying that the stream is already read.
This error is because I'm using koaBody()
in the middleware to read request.body.numPlayers
.
The following line also uses koaBody()
but fails, since the stream has already been read.
https://github.com/boardgameio/boardgame.io/blob/afc16c6ec20d35665e947894af921893584d1c0f/src/server/api.ts#L233
I suggest making koaBody()
happen only if it did not already.
Willing to write the code for this if you think this makes sense.
Do I understand correctly that the middleware runs before the router so the body hasn’t been parsed yet? Definitely happy to look at a PR that refactors this! Either by making sure koaBody
is called before any middleware to make request.body
available everywhere or do what you suggest.
Hello, wondering if anyone has worked on this--I have the exact same issue.