Add some sanity checks for common first-startup issues

This commit is contained in:
Calvin Montgomery 2019-02-10 10:22:16 -08:00
parent 66d81ffb22
commit c6f9b1611e
4 changed files with 67 additions and 1 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.63.1",
"version": "3.63.2",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -245,6 +245,28 @@ function loadEmailConfig() {
function preprocessConfig(cfg) {
// Root domain should start with a . for cookies
var root = cfg.http["root-domain"];
if (/127\.0\.0\.1|localhost/.test(root)) {
LOGGER.warn(
"Detected 127.0.0.1 or localhost in root-domain '%s'. This server " +
"will not work from other computers! Set root-domain to the domain " +
"the website will be accessed from (e.g. example.com)",
root
);
}
if (/^http/.test(root)) {
LOGGER.warn(
"root-domain '%s' should not contain http:// or https://, removing it",
root
);
root = root.replace(/^https?:\/\//, "");
}
if (/:\d+$/.test(root)) {
LOGGER.warn(
"root-domain '%s' should not contain a trailing port, removing it",
root
);
root = root.replace(/:\d+$/, "");
}
root = root.replace(/^\.*/, "");
cfg.http["root-domain"] = root;
if (root.indexOf(".") !== -1 && !net.isIP(root)) {
@ -328,6 +350,13 @@ function preprocessConfig(cfg) {
cfg.io["ipv4-default"] = cfg.io["ipv4-ssl"] || cfg.io["ipv4-nossl"];
cfg.io["ipv6-default"] = cfg.io["ipv6-ssl"] || cfg.io["ipv6-nossl"];
if (/127\.0\.0\.1|localhost/.test(cfg.io["ipv4-default"])) {
LOGGER.warn(
"socket.io is bound to localhost, this server will be inaccessible " +
"from other computers!"
);
}
// Generate RegExps for reserved names
var reserved = cfg["reserved-names"];
for (var key in reserved) {

View File

@ -488,6 +488,18 @@ module.exports = {
} else {
const server = http.createServer().listen(bind.port, bind.ip);
servers.push(server);
server.on("error", error => {
if (error.code === "EADDRINUSE") {
LOGGER.fatal(
"Could not bind %s: address already in use. Check " +
"whether another application has already bound this " +
"port, or whether another instance of this server " +
"is running.",
id
);
process.exit(1);
}
});
}
uniqueListenAddresses.add(id);

View File

@ -24,6 +24,7 @@ module.exports = {
fs.exists(gdvttpath, function (exists) {
exists || fs.mkdirSync(gdvttpath);
});
singleton = new Server();
return singleton;
},
@ -161,6 +162,18 @@ var Server = function () {
if (bind.https && Config.get("https.enabled")) {
self.servers[id] = https.createServer(opts, self.express)
.listen(bind.port, bind.ip);
self.servers[id].on("error", error => {
if (error.code === "EADDRINUSE") {
LOGGER.fatal(
"Could not bind %s: address already in use. Check " +
"whether another application has already bound this " +
"port, or whether another instance of this server " +
"is running.",
id
);
process.exit(1);
}
});
self.servers[id].on("clientError", function (err, socket) {
try {
socket.destroy();
@ -170,6 +183,18 @@ var Server = function () {
});
} else if (bind.http) {
self.servers[id] = self.express.listen(bind.port, bind.ip);
self.servers[id].on("error", error => {
if (error.code === "EADDRINUSE") {
LOGGER.fatal(
"Could not bind %s: address already in use. Check " +
"whether another application has already bound this " +
"port, or whether another instance of this server " +
"is running.",
id
);
process.exit(1);
}
});
self.servers[id].on("clientError", function (err, socket) {
try {
socket.destroy();