Created
March 29, 2021 07:48
-
-
Save ioslh/101dd2957f25693be9726dfacb628ccc to your computer and use it in GitHub Desktop.
mount connect/express to koa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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