mounting into an express app
See original GitHub issueI’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:
- Created 7 years ago
- Comments:16 (11 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
In case you didn’t get a notification, I opened #847 for this.
@nickb1080 Ooh, that’s a tricky one, I thought
handleRequest
returned the promise. I’ll make a PR for that now.