-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to access httpServer instance? #129
Comments
+1 |
1 similar comment
+1 |
I found a solution. In your initializer folder, add this file : 00_server.js : module.exports = function() {
var app = this.express;
this.server = require('http').createServer(app);
}; And XX_socketio.js (replace XX by correct number of initializer) : var socketio = require('socket.io');
module.exports = function() {
this.io = socketio.listen(this.server);
// socket.io config and routes
}; |
Cool! would this work with an older version? (0.3.x?) |
i try this with latest locomotive version. Sorry |
It seems that it does not work. Indeed, the server created here is different from the locomotive. |
Ok, after research, locomotive initialize the http server after all initializers and, in boot function it is not possible to retrieve the server object. In this case, it's impossible to use socket.io with locomotive 0.4.x |
Good to know! Thanks for sharing :) |
After others tests, i finally find this and launch socket.io 💃 In your new server.js, remove the line for init httpServer : app.phase(locomotive.boot.httpServer({ address: address, port: port })); In initializers/00_server.js : module.exports = function(done) {
var app = this.express,
port = process.env.PORT || 3000,
address = '0.0.0.0';
if(this.env == 'test'){
port = 3030;
}
var self = this;
require('http').createServer(app).listen(port, address, function() {
var addr = this.address();
console.log('listening on %s:%d', addr.address, addr.port);
self.server = this;
done();
});
}; And in initializers/XX_socketio.js : var socketio = require('socket.io');
module.exports = function() {
this.io = socketio.listen(this.server);
// socket.io config and routes
}; After that, it works fine ;) |
This deserves a bookmark :) Thanks again for sharing. |
Hi there, I have made a plugin for locomotive, to use Primus (abstraction layer over many websockets engines). https://github.com/OtaK/locomotive-primus It does what you're asking (exposing http server in app instance). 👍 :-) |
will definitively give this a try asap... wow, nice idea! |
Just for the record, Jared, the author of Locomotive knows about it and featured it here : https://github.com/jaredhanson/locomotive/wiki/Modules Don't hesitate if you have any questions about it ! |
I don't find a way to access httpServer instance which is created at boot phase, and this issue has been discussed in issues #87, #88, #125.
Pull request #88 doesn't be merged into 0.4.x.
It's request to expose httpServer instance for initializers to support socket.io listen to the same port as http service.
The text was updated successfully, but these errors were encountered: