Does not play well with koa-compose
See original GitHub issueApp always sends 404 Not found
when koa-bodyparser
is wrapped inside koa-compose
{
"koa": "^2.4.1",
"koa-bodyparser": "^2.5.0",
"koa-compose": "^4.0.0"
}
const Koa = require('koa')
const compose = require('koa-compose')
const bodyparser = require('koa-bodyparser')
const app = new Koa()
// app.use(bodyparser()) // works
app.use(compose([bodyparser()])) // send 404
app.use((ctx) => {
ctx.body = 'Hello World!'
})
app.listen(3000)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Koa Auth flow with compose - Stack Overflow
Answering my own question here, turns out not that hard import compose from 'koa-compose'; import convert from 'koa-convert'; ...
Read more >Mastering Koa Middleware - Medium
Learn how Koa's middleware system works and how you can use it to write any kind of middleware.
Read more >20 Camping Games for Families & Kids - KOA
Outdoor camping games are great because they let everyone get active, soak up the sun and get fresh air. Here are some of...
Read more >Let's build a REST API with Koa.js and test with Jest! - codeburst
Koa does not bundle any middleware within core, and provides an elegant ... you can do with the middleware, as well as accomplish...
Read more >From express to Koa. 'How using async/await push me from…
The following will do the same as the code above but: ... We write again and again try {} catch(error){ next(error) } Not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
When meet this, we should check other middleware’s calling of
next()
.If a middleware is a common function, we should call like:
But not:
The solution is add keyword
return
and let the middleware returns the promise.I struggle this for several hours, so write it down, may it helps.
Finally, see this article for more detail.
This issue is invalid.
@yadwinderpaul You’re using an old version of koa-bodyparse which is not compliant with Koa 2 (and thus compose 4 and 3 which is what Koa is using currently).
@codinggirl It makes no sense to break the promise flow with synchronous middleware currently. And not calling next is a completely valid use case. Having a guard in this repo (even though one could assume next is always called after this specific middleware) can be very confusing.