Skip to content

Instantly share code, notes, and snippets.

@ioslh
Created March 29, 2021 07:48
Show Gist options
  • Save ioslh/101dd2957f25693be9726dfacb628ccc to your computer and use it in GitHub Desktop.
Save ioslh/101dd2957f25693be9726dfacb628ccc to your computer and use it in GitHub Desktop.
mount connect/express to koa
import koa from 'koa'
import middlewareForExpressOrConnect from './path/some-middleware'
const app = new koa()
app.use(async (ctx, next) => {
const { req, res } = ctx
return new Promise((resolve, reject) => {
middlewareForExpressOrConnect(req, res, (err) => {
if (err) {
reject(err)
} else {
next().then(resolve)
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment