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' user: 'cytube3'
password: '' 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 server details
http: http:
# If you want to bind a specific IP, put it here, otherwise leave empty # Even though you may specify multiple ports to listen on for HTTP above,
host: '' # one port must be specified as default for the purposes of generating
port: 8080 # links with the appropriate port
default-port: 8080
domain: 'http://localhost' domain: 'http://localhost'
# Specifies the root domain for cookies. If you have multiple domains # 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 # e.g. a.example.com and b.example.com, the root domain is example.com
@ -30,7 +62,10 @@ http:
# HTTPS server details # HTTPS server details
https: https:
enabled: false 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' domain: 'https://localhost'
keyfile: 'localhost.key' keyfile: 'localhost.key'
passphrase: '' passphrase: ''
@ -51,7 +86,10 @@ io:
# If the root of this domain is not the same as the root of your HTTP domain # 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. # (or HTTPS if SSL is enabled), logins won't work.
domain: 'http://localhost' 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 # limit the number of concurrent socket connections per IP address
ip-connection-limit: 10 ip-connection-limit: 10

View file

@ -36,13 +36,16 @@ var defaults = {
], ],
http: { http: {
domain: "http://localhost", domain: "http://localhost",
"default-port": 8080,
"root-domain": "localhost", "root-domain": "localhost",
"alt-domains": ["127.0.0.1"], "alt-domains": ["127.0.0.1"],
minify: false, minify: false,
"cache-ttl": 0 "cache-ttl": 0
}, },
https: { https: {
enabled: false,
domain: "https://localhost", domain: "https://localhost",
"default-port": 8443,
keyfile: "localhost.key", keyfile: "localhost.key",
passphrase: "", passphrase: "",
certfile: "localhost.cert", certfile: "localhost.cert",
@ -50,6 +53,7 @@ var defaults = {
}, },
io: { io: {
domain: "http://localhost", domain: "http://localhost",
"default-port": 1337,
"ip-connection-limit": 10 "ip-connection-limit": 10
}, },
mail: { mail: {
@ -158,6 +162,40 @@ exports.load = function (file) {
}; };
function preprocessConfig(cfg) { 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 // Root domain should start with a . for cookies
var root = cfg.http["root-domain"]; var root = cfg.http["root-domain"];
root = root.replace(/^\.*/, ""); root = root.replace(/^\.*/, "");
@ -188,7 +226,7 @@ function preprocessConfig(cfg) {
if (!cfg.http["full-address"]) { if (!cfg.http["full-address"]) {
var httpfa = cfg.http.domain; var httpfa = cfg.http.domain;
if (cfg.http.port !== 80) { if (cfg.http.port !== 80) {
httpfa += ":" + cfg.http.port; httpfa += ":" + cfg.http["default-port"];
} }
cfg.http["full-address"] = httpfa; cfg.http["full-address"] = httpfa;
} }
@ -196,7 +234,7 @@ function preprocessConfig(cfg) {
if (!cfg.https["full-address"]) { if (!cfg.https["full-address"]) {
var httpsfa = cfg.https.domain; var httpsfa = cfg.https.domain;
if (cfg.https.port !== 443) { if (cfg.https.port !== 443) {
httpsfa += ":" + cfg.https.port; httpsfa += ":" + cfg.https["default-port"];
} }
cfg.https["full-address"] = httpsfa; cfg.https["full-address"] = httpsfa;
} }

View file

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

View file

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