Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding middleware causes crash #1107

Open
YoavHortman opened this issue Oct 31, 2022 · 2 comments
Open

Adding middleware causes crash #1107

YoavHortman opened this issue Oct 31, 2022 · 2 comments

Comments

@YoavHortman
Copy link

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.

router.post('/games/:name/:id/join', koaBody(), async (ctx) => {

I suggest making koaBody() happen only if it did not already.

Willing to write the code for this if you think this makes sense.

@delucis
Copy link
Member

delucis commented Oct 31, 2022

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.

@kevinddchen
Copy link
Contributor

Hello, wondering if anyone has worked on this--I have the exact same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants