https://github.com/bttmly/koa-within-express
Tiny example of embedding a Koa application within an Express application
https://github.com/bttmly/koa-within-express
Last synced: 3 months ago
JSON representation
Tiny example of embedding a Koa application within an Express application
- Host: GitHub
- URL: https://github.com/bttmly/koa-within-express
- Owner: bttmly
- Created: 2017-03-08T19:28:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-05T04:11:49.000Z (about 8 years ago)
- Last Synced: 2025-01-08T22:00:01.589Z (4 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-within-express
A [recent change](https://github.com/koajs/koa/pull/848) to Koa makes interop with Express much easier. This repo contains a tiny example of how to have Express handle some routes, pass control to Koa, and then have Koa pass control back to Express if it can't handle a request.
## Notes
- Must override `ctx.onerror` to catch errors and pass them back to Express for handling
- Be sure not to call `next` if Koa handled the response
- Need some way of detecting if some handler in the Koa middleware stack is trying to send a response. Here the approach is to null out `res.statusCode` and see if it was set after the middleware stack has run.
- Be sure to reset the response status code to 200 if not handling the response