question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not play well with koa-compose

See original GitHub issue

App 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
codinggirlcommented, Feb 25, 2018

When meet this, we should check other middleware’s calling of next().

If a middleware is a common function, we should call like:

return next()

But not:

next()

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.

0reactions
fl0wcommented, Oct 28, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found