Convert server definitions to be more flexible
This commit is contained in:
parent
04dbb3444b
commit
fb0533bd94
4 changed files with 67 additions and 50 deletions
|
|
@ -119,27 +119,29 @@ function handleConnection(sock) {
|
|||
|
||||
module.exports = {
|
||||
init: function (srv) {
|
||||
var ioport = Config.get("io.port");
|
||||
var webport = Config.get("http.port");
|
||||
var app;
|
||||
if (ioport !== webport) {
|
||||
app = require("express")().listen(ioport, Config.get("http.host"));
|
||||
srv.ioWeb = app;
|
||||
} else {
|
||||
app = srv.express;
|
||||
}
|
||||
Config.get("listen").forEach(function (bind) {
|
||||
if (!bind.io) {
|
||||
return;
|
||||
}
|
||||
var id = bind.ip + ":" + bind.port;
|
||||
if (id in srv.ioServers) {
|
||||
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
srv.io = sio.listen(app);
|
||||
srv.io.set("log level", 1);
|
||||
srv.io.set("authorization", handleAuth);
|
||||
srv.io.on("connection", handleConnection);
|
||||
|
||||
if (Config.get("https.enabled")) {
|
||||
srv.ioSecure = sio.listen(srv.https);
|
||||
srv.ioSecure.set("log level", 1);
|
||||
srv.ioSecure.set("authorization", handleAuth);
|
||||
srv.ioSecure.on("connection", handleConnection);
|
||||
}
|
||||
var io = null;
|
||||
if (id in srv.servers) {
|
||||
io = srv.ioServers[id] = sio.listen(srv.servers[id]);
|
||||
} else {
|
||||
io = srv.ioServers[id] = sio.listen(bind.port, bind.ip);
|
||||
}
|
||||
|
||||
if (io) {
|
||||
io.set("log level", 1);
|
||||
io.set("authorization", handleAuth);
|
||||
io.on("connection", handleConnection);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue