Update config.template.yaml and server files for new listen syntax

This commit is contained in:
calzoneman 2014-04-11 10:52:51 -05:00
parent fb0533bd94
commit 3567087c48
4 changed files with 90 additions and 20 deletions

View file

@ -36,13 +36,16 @@ var defaults = {
],
http: {
domain: "http://localhost",
"default-port": 8080,
"root-domain": "localhost",
"alt-domains": ["127.0.0.1"],
minify: false,
"cache-ttl": 0
},
https: {
enabled: false,
domain: "https://localhost",
"default-port": 8443,
keyfile: "localhost.key",
passphrase: "",
certfile: "localhost.cert",
@ -50,6 +53,7 @@ var defaults = {
},
io: {
domain: "http://localhost",
"default-port": 1337,
"ip-connection-limit": 10
},
mail: {
@ -158,6 +162,40 @@ exports.load = function (file) {
};
function preprocessConfig(cfg) {
/* Detect 3.0.0-style config and warng the user about it */
if ("host" in cfg.http || "port" in cfg.http || "port" in cfg.https) {
Logger.syslog.log("[WARN] The method of specifying which IP/port to bind has "+
"changed. The config loader will try to handle this "+
"automatically, but you should read config.template.yaml "+
"and change your config.yaml to the new format.");
cfg.listen = [
{
ip: cfg.http.host,
port: cfg.http.port,
http: true
},
{
ip: cfg.http.host,
port: cfg.io.port,
io: true
}
];
if (cfg.https.enabled) {
cfg.listen.push(
{
ip: cfg.http.host,
port: cfg.https.port,
https: true,
io: true
}
);
}
cfg.http["default-port"] = cfg.http.port;
cfg.https["default-port"] = cfg.https.port;
cfg.io["default-port"] = cfg.io.port;
}
// Root domain should start with a . for cookies
var root = cfg.http["root-domain"];
root = root.replace(/^\.*/, "");
@ -188,7 +226,7 @@ function preprocessConfig(cfg) {
if (!cfg.http["full-address"]) {
var httpfa = cfg.http.domain;
if (cfg.http.port !== 80) {
httpfa += ":" + cfg.http.port;
httpfa += ":" + cfg.http["default-port"];
}
cfg.http["full-address"] = httpfa;
}
@ -196,7 +234,7 @@ function preprocessConfig(cfg) {
if (!cfg.https["full-address"]) {
var httpsfa = cfg.https.domain;
if (cfg.https.port !== 443) {
httpsfa += ":" + cfg.https.port;
httpsfa += ":" + cfg.https["default-port"];
}
cfg.https["full-address"] = httpsfa;
}

View file

@ -49,11 +49,6 @@ var Server = function () {
var self = this;
self.channels = [],
self.express = null;
self.http = null;
self.https = null;
self.io = null;
self.ioWeb = null;
self.ioSecure = null;
self.db = null;
self.api = null;
self.announcement = null;
@ -99,7 +94,7 @@ var Server = function () {
return;
}
if (bind.https) {
if (bind.https && Config.get("https.enabled")) {
self.servers[id] = https.createServer(opts, self.express)
.listen(bind.port, bind.ip);
} else if (bind.http) {
@ -246,9 +241,8 @@ Server.prototype.announce = function (data) {
} else {
this.announcement = data;
db.setAnnouncement(data);
this.io.sockets.emit("announcement", data);
if (this.ioSecure) {
this.ioSecure.sockets.emit("announcement", data);
for (var id in this.ioServers) {
this.ioServers[id].sockets.emit("announcement", data);
}
}
};

View file

@ -112,7 +112,7 @@ function handleChannel(req, res) {
if (req.secure) {
sio = Config.get("https.full-address");
} else {
sio = Config.get("io.domain") + ":" + Config.get("io.port");
sio = Config.get("io.domain") + ":" + Config.get("io.default-port");
}
sio += "/socket.io/socket.io.js";
@ -159,9 +159,9 @@ function handleSocketConfig(req, res) {
res.type("application/javascript");
var io_url = Config.get("io.domain") + ":" + Config.get("io.port");
var web_url = Config.get("http.domain") + ":" + Config.get("http.port");
var ssl_url = Config.get("https.domain") + ":" + Config.get("https.port");
var io_url = Config.get("io.domain") + ":" + Config.get("io.default-port");
var web_url = Config.get("http.domain") + ":" + Config.get("http.default-port");
var ssl_url = Config.get("https.domain") + ":" + Config.get("https.default-port");
res.send("var IO_URL='"+io_url+"',WEB_URL='"+web_url+"',SSL_URL='" + ssl_url +
"',ALLOW_SSL="+Config.get("https.enabled")+";" +
(Config.get("https.enabled") ?