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

@ -9,11 +9,43 @@ mysql:
user: 'cytube3'
password: ''
# Define IPs/ports to listen on
# Each entry MUST define ip and port (ip can be '' to bind all available addresses)
# Each entry should set http, https, and/or io to true to listen for the corresponding
# service on that port. http/io and https/io can be combined, but if http and https
# are both specified, only https will be bound to that port.
#
# NOTE: You can technically bind an IPv6 address this way, but much of the code has not
# yet been updated to work with IPv6 addresses (ban ranges, IP masking, etc.)
# IPv6 support is planned, and the below method of binding servers is one step in that
# direction
listen:
# Default HTTP server - default interface, port 8080
- ip: ''
port: 8080
http: true
# Uncomment below to enable HTTPS/SSL websockets
# Note that you must also set https->enabled = true in the https definition
# - ip: ''
# port: 8443
# https: true
# io: true
# Default Socket.IO server - default interface, port 1337
- ip: ''
port: 1337
io: true
# Example of how to bind an extra port to HTTP and Socket.IO
# - ip: ''
# port: 8081
# http: true
# io: true
# HTTP server details
http:
# If you want to bind a specific IP, put it here, otherwise leave empty
host: ''
port: 8080
# Even though you may specify multiple ports to listen on for HTTP above,
# one port must be specified as default for the purposes of generating
# links with the appropriate port
default-port: 8080
domain: 'http://localhost'
# Specifies the root domain for cookies. If you have multiple domains
# e.g. a.example.com and b.example.com, the root domain is example.com
@ -30,7 +62,10 @@ http:
# HTTPS server details
https:
enabled: false
port: 8443
# Even though you may specify multiple ports to listen on for HTTPS above,
# one port must be specified as default for the purposes of generating
# links with the appropriate port
default-port: 8443
domain: 'https://localhost'
keyfile: 'localhost.key'
passphrase: ''
@ -51,7 +86,10 @@ io:
# If the root of this domain is not the same as the root of your HTTP domain
# (or HTTPS if SSL is enabled), logins won't work.
domain: 'http://localhost'
port: 1337
# Even though you may specify multiple ports to listen on for HTTP above,
# one port must be specified as default for the purposes of generating
# links with the appropriate port
default-port: 1337
# limit the number of concurrent socket connections per IP address
ip-connection-limit: 10

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") ?