Closed braksator closed 5 years ago
Oh, ok just got rid of the original listen() calls.
I got it working like so:
app.listen = function() {
app.server.listen.apply(app.server, arguments);
return app.server;
}
http.createServer(app.callback());
app.listen(port);
if (/* my ssl conditions to check keys/certs */) {
https.createServer(app.callback());
app.listen(sslPort);
}
At least the http part works, I don't have keys/certs set up to test SSL yet.
I would still appreciate any comments, feedback, or suggestions to make this more succinct. Cheers!
Hey Braksator,
You've got it. As convoluted as it is, that's currently the solution. There is not yet a convenience function for this behavior, but I'll put it on the list.
// *If* you had manually attached an `app.server` yourself, you should do:
app.listen = function() {
app.server.listen.apply(app.server, arguments);
return app.server;
}
/* YOUR HTTP SERVER CODE HERE */
// app.listen is mapped to app.server.listen, so you can just do:
app.listen( process.env.PORT || 3000 );
The example code uses app.listen but I'm using the http.createServer method outlined here: https://github.com/koajs/koa/blob/master/docs/api/index.md#applisten
This lets socket.io to work:
This doesn't work:
I figured perhaps the section on Attaching To Existing Projects would get me out of this jam (https://www.npmjs.com/package/koa-socket-2#attaching-to-existing-projects)
So I added the last two code blocks (from // If you had manually... onwards) but that just tries to start a second server on the same port which doesn't work.
I'm not sure what to do here.