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.

mounting into an express app

See original GitHub issue

I’m exploring migrating a large production Express app to koa v2 (so all of this applies to the promise API of v2). The koajs.com docs say for app.callback():

“You may also use this callback function to mount your koa app in a Connect/Express app.”

However, it seems like you must mount a koa app at the “bottom” of your Express app since koa will never call next() to yield control back to express (like in the 404 case). I can’t see an obvious work around for this currently. If the function returned by callback returned the promise, I think something like the following would work:

const koaCallback = koaApp.callback();
expressApp.use(function (req, res, next) {
  koaCallback(req, res)
    .then(function () {
      // not sure exactly how to detect this but seems doable
      if (!koaSentResponse(res)) {
        next() // let express keep processing this request
      }
   });
});

Perhaps somewhat related – what’s the use case for setting ctx.respond to false?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
PlasmaPowercommented, Oct 28, 2016

In case you didn’t get a notification, I opened #847 for this.

2reactions
PlasmaPowercommented, Oct 28, 2016

@nickb1080 Ooh, that’s a tricky one, I thought handleRequest returned the promise. I’ll make a PR for that now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does mounting apps in Express work - node.js
So the answer is: A mounted app will have the middleware ... The next callback tells express to run the next function in...
Read more >
Express.js Mount Event - GeeksforGeeks
The mount event is fired on a sub-app when it is mounted on a parent app and the parent app is basically passed...
Read more >
Installing - Express.js
Assuming you've already installed Node.js, create a directory to hold your application, and make that your working directory. ... Use the npm init...
Read more >
Node js Tutorial | Install Express Application & Basic Routing
Learn How to Create a basic Structure of Node Express.js. Suppose you want to build CRUD Web Application using Express JS, then first...
Read more >
How to setup Express.js in Node.js - Robin Wieruch
How to setup Express.js in Node.js ; 3000 · 'Example app listening on port 3000!' ; app.get('/', (req, res) => {. res.send('Hello World!');....
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