mirror of https://github.com/calzoneman/sync.git
Convert server definitions to be more flexible
This commit is contained in:
parent
04dbb3444b
commit
fb0533bd94
|
@ -22,9 +22,19 @@ var defaults = {
|
|||
user: "cytube3",
|
||||
password: ""
|
||||
},
|
||||
listen: [
|
||||
{
|
||||
ip: "",
|
||||
port: 8080,
|
||||
http: true,
|
||||
},
|
||||
{
|
||||
ip: "",
|
||||
port: 1337,
|
||||
io: true
|
||||
}
|
||||
],
|
||||
http: {
|
||||
host: "",
|
||||
port: 8080,
|
||||
domain: "http://localhost",
|
||||
"root-domain": "localhost",
|
||||
"alt-domains": ["127.0.0.1"],
|
||||
|
@ -32,8 +42,6 @@ var defaults = {
|
|||
"cache-ttl": 0
|
||||
},
|
||||
https: {
|
||||
enabled: false,
|
||||
port: 8443,
|
||||
domain: "https://localhost",
|
||||
keyfile: "localhost.key",
|
||||
passphrase: "",
|
||||
|
@ -42,7 +50,6 @@ var defaults = {
|
|||
},
|
||||
io: {
|
||||
domain: "http://localhost",
|
||||
port: 1337,
|
||||
"ip-connection-limit": 10
|
||||
},
|
||||
mail: {
|
||||
|
|
|
@ -663,9 +663,8 @@ module.exports.loadAnnouncement = function () {
|
|||
|
||||
var sv = Server.getServer();
|
||||
sv.announcement = announcement;
|
||||
sv.io.sockets.emit("announcement", announcement);
|
||||
if (sv.ioSecure) {
|
||||
sv.ioSecure.sockets.emit("announcement", announcement);
|
||||
for (var id in sv.ioServers) {
|
||||
sv.ioServers[id].sockets.emit("announcement", announcement);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
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 (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);
|
||||
}
|
||||
if (io) {
|
||||
io.set("log level", 1);
|
||||
io.set("authorization", handleAuth);
|
||||
io.on("connection", handleConnection);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@ var Server = function () {
|
|||
self.httplog = null;
|
||||
self.infogetter = null;
|
||||
self.torblocker = null;
|
||||
self.servers = {};
|
||||
self.ioServers = {};
|
||||
|
||||
// database init ------------------------------------------------------
|
||||
var Database = require("./database");
|
||||
|
@ -73,30 +75,37 @@ var Server = function () {
|
|||
require("./web/webserver").init(self.express);
|
||||
|
||||
// http/https/sio server init -----------------------------------------
|
||||
if (Config.get("https.enabled")) {
|
||||
var key = fs.readFileSync(path.resolve(__dirname, "..",
|
||||
Config.get("https.keyfile")));
|
||||
var cert = fs.readFileSync(path.resolve(__dirname, "..",
|
||||
Config.get("https.certfile")));
|
||||
var ca = undefined;
|
||||
if (Config.get("https.cafile")) {
|
||||
ca = fs.readFileSync(path.resolve(__dirname, "..",
|
||||
Config.get("https.cafile")));
|
||||
}
|
||||
|
||||
var opts = {
|
||||
key: key,
|
||||
cert: cert,
|
||||
passphrase: Config.get("https.passphrase"),
|
||||
ca: ca
|
||||
};
|
||||
|
||||
self.https = https.createServer(opts, self.express)
|
||||
.listen(Config.get("https.port"));
|
||||
var key = fs.readFileSync(path.resolve(__dirname, "..",
|
||||
Config.get("https.keyfile")));
|
||||
var cert = fs.readFileSync(path.resolve(__dirname, "..",
|
||||
Config.get("https.certfile")));
|
||||
var ca = undefined;
|
||||
if (Config.get("https.cafile")) {
|
||||
ca = fs.readFileSync(path.resolve(__dirname, "..",
|
||||
Config.get("https.cafile")));
|
||||
}
|
||||
|
||||
self.http = self.express.listen(Config.get("http.port"),
|
||||
Config.get("http.host") || undefined);
|
||||
var opts = {
|
||||
key: key,
|
||||
cert: cert,
|
||||
passphrase: Config.get("https.passphrase"),
|
||||
ca: ca
|
||||
};
|
||||
|
||||
Config.get("listen").forEach(function (bind) {
|
||||
var id = bind.ip + ":" + bind.port;
|
||||
if (id in self.servers) {
|
||||
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bind.https) {
|
||||
self.servers[id] = https.createServer(opts, self.express)
|
||||
.listen(bind.port, bind.ip);
|
||||
} else if (bind.http) {
|
||||
self.servers[id] = self.express.listen(bind.port, bind.ip);
|
||||
}
|
||||
});
|
||||
|
||||
require("./io/ioserver").init(self);
|
||||
|
||||
|
|
Loading…
Reference in New Issue