Mount Koajs app on top of Express

From koajs.com:

app.callback ()

Returns a callback function suitable for the http.createServer () method to process the request. You can also use this callback function to mount your koa application in a Connect / Express application.

Now I have an Express application that is already starting its own HTTP server. How to mount a koa application on top of this existing server so that it has the same port?

Would I include a koa application like Express middlware? Do I still use app.callback()for this?

+3
source share
2 answers

expressapp.use(koaapp.callback()) . , koaapp.callback() next, - koaapp .

, API

var koaapp = koa()
var expressapp = express()
http.createServer(req, res) {
  if (true) koaapp(req, res);
  else expressapp(req, res);
})
+2

/prefix, -

var http = require('http');
var expressApp = require('express');
var koaApp = require('koa');

// ...

expressApp.use('/prefix', http.createServer(koaApp.callback()));
-1

All Articles