-
Notifications
You must be signed in to change notification settings - Fork 716
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
Koa example in Typescript - cant modify stream #1143
Comments
For people in the future3 who have this problem:
this will clobber the existing body and replace it with your own |
Your specific use-case may be handled by the However, I also want to add middleware to modify the server behavior, e.g. invalidate player names upon joining a match if another player has that same name. #1107 is another issue on the same topic. |
@webrunner42 Thank you very much for your snippet! 🎉 I was able to arrive at a good workaround. My use-case was pretty simple, since I just needed to intercept the body and then pass it without any changes. For reference, this is what I used:
It seems that a more permanent fix may be added to the koa library: koajs/bodyparser#127. |
I'm a trading card game, and looking for a way to set up the decks at the beginning of the match.
The docs have an example :
but I'm not sure if something has changed since here but using koa, the body isn't parsed yet when we get to this point, so ctx.request.body doesnt exist. If we try to parse the body here (using koaBody() or something) then later, since the body is already parsed, the boardgame.io game creation ui breaks because the stream is already closed and no longer readable.
I've tried something like this:
but it gets clobbered by koabody.
And obviously I cant make the changes -after- the game creation api does it's thing because the game constructor is already called.
Is there a work around? making the changes and writing 'back' a new stream to the context? A setting that makes bgio use the previously parsed body and skip using koaBody?
The text was updated successfully, but these errors were encountered: