-
Notifications
You must be signed in to change notification settings - Fork 44
Description
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
