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

parse.json function not working after calling it in earlier middleware #81

Open
cleverocheck opened this issue Nov 12, 2021 · 1 comment

Comments

@cleverocheck
Copy link

Hello everyone, I am writing a Koa application in TS and I have one problem with the co-body library. It lies in the fact that during one request the maximum number of normally working calls to the parse.json function = 1 (on the second call to the parse.json function, the request always ends with just gateway timeout). And as a result, I have to make crutches in the form of a call to parse.json on one of the most faithful middleware and transfer it to the bottom through ctx, which is why the typing is not done in the best way, the purity of the code suffers and this is lower in performance (because sometimes I no need to call parse.json at all)

An example of a code showing this problem (the parse.json function call is not included in separate middleware, but there is no difference as such)

const koa = require('koa')
const parse = require('co-body')

const app = new koa()

app.use(async ctx => {
    const bodyOk = await parse.json(ctx.req)
    console.log('Body is ok', bodyOk)
    await parse.json(ctx.req)
    console.log('Will never reach it log...')
})

const PORT = 3000
app.listen(PORT, () => console.log(`API listening on ${PORT}`))

I'm testing this problem through Postman with this content

image

@cleverocheck
Copy link
Author

Any updates?

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

1 participant