mirror of https://github.com/calzoneman/sync.git
Add /reload console command, change some internal config
This commit is contained in:
parent
2bd6a207ba
commit
4e2c6d486b
17
index.js
17
index.js
|
@ -25,3 +25,20 @@ if (!Config.get("debug")) {
|
|||
sv.shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
var stdinbuf = "";
|
||||
process.stdin.on("data", function (data) {
|
||||
stdinbuf += data;
|
||||
if (stdinbuf.indexOf("\n") !== -1) {
|
||||
var line = stdinbuf.substring(0, stdinbuf.indexOf("\n"));
|
||||
stdinbuf = stdinbuf.substring(stdinbuf.indexOf("\n") + 1);
|
||||
handleLine(line);
|
||||
}
|
||||
});
|
||||
|
||||
function handleLine(line) {
|
||||
if (line === "/reload") {
|
||||
Logger.syslog.log("Reloading config");
|
||||
Config.load("config.yaml");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,24 +133,50 @@ exports.load = function (file) {
|
|||
mailconfig = cfg.mail.config;
|
||||
delete cfg.mail.config;
|
||||
}
|
||||
|
||||
merge(cfg, defaults, "config");
|
||||
|
||||
cfg.mail.config = mailconfig;
|
||||
|
||||
preprocessConfig(cfg);
|
||||
Logger.syslog.log("Loaded configuration from " + file);
|
||||
};
|
||||
|
||||
function preprocessConfig(cfg) {
|
||||
// Root domain should start with a . for cookies
|
||||
var root = cfg.http["root-domain"];
|
||||
root = "." + root.replace(/^\.*/, "");
|
||||
cfg.http["root-domain"] = root;
|
||||
|
||||
// Setup nodemailer
|
||||
cfg.mail.nodemailer = nodemailer.createTransport(
|
||||
cfg.mail.transport,
|
||||
cfg.mail.config
|
||||
);
|
||||
|
||||
// Debug
|
||||
if (process.env.DEBUG === "1" || process.env.DEBUG === "true") {
|
||||
cfg.debug = true;
|
||||
} else {
|
||||
cfg.debug = false;
|
||||
}
|
||||
|
||||
// Strip trailing slashes from domains
|
||||
cfg.http.domain = cfg.http.domain.replace(/\/*$/, "");
|
||||
cfg.https.domain = cfg.https.domain.replace(/\/*$/, "");
|
||||
|
||||
// HTTP/HTTPS domains with port numbers
|
||||
var httpfa = cfg.http.domain;
|
||||
if (cfg.http.port !== 80) {
|
||||
httpfa += ":" + cfg.http.port;
|
||||
}
|
||||
cfg.http["full-address"] = httpfa;
|
||||
|
||||
var httpsfa = cfg.https.domain;
|
||||
if (cfg.https.port !== 443) {
|
||||
httpsfa += ":" + cfg.https.port;
|
||||
}
|
||||
cfg.https["full-address"] = httpsfa;
|
||||
|
||||
// Generate RegExps for reserved names
|
||||
var reserved = cfg["reserved-names"];
|
||||
for (var key in reserved) {
|
||||
if (reserved[key] && reserved[key].length > 0) {
|
||||
|
@ -159,9 +185,8 @@ exports.load = function (file) {
|
|||
reserved[key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.syslog.log("Loaded configuration from " + file);
|
||||
};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a configuration value with the given key
|
||||
|
|
|
@ -14,8 +14,8 @@ function merge(locals) {
|
|||
siteTitle: Config.get("html-template.title"),
|
||||
siteDescription: Config.get("html-template.description"),
|
||||
siteAuthor: "Calvin 'calzoneman' 'cyzon' Montgomery",
|
||||
loginDomain: Config.get("https.enabled") ? Config.get("https.domain")+":"+Config.get("https.port")
|
||||
: Config.get("http.domain")+":"+Config.get("http.port")
|
||||
loginDomain: Config.get("https.enabled") ? Config.get("https.full-address")
|
||||
: Config.get("http.full-address")
|
||||
};
|
||||
if (typeof locals !== "object") {
|
||||
return _locals;
|
||||
|
@ -30,7 +30,7 @@ function merge(locals) {
|
|||
* Renders and serves a jade template
|
||||
*/
|
||||
function sendJade(res, view, locals) {
|
||||
if (!(view in cache) || process.env["DEBUG"]) {
|
||||
if (!(view in cache) || Config.get("debug")) {
|
||||
var file = path.join(templates, view + ".jade");
|
||||
var fn = jade.compile(fs.readFileSync(file), {
|
||||
filename: file,
|
||||
|
|
|
@ -64,12 +64,7 @@ function logRequest(req, status) {
|
|||
|
||||
function cookieall(res, name, val, opts) {
|
||||
res.cookie(name, val, opts);
|
||||
|
||||
opts.domain = Config.get("http.root-domain");
|
||||
if (Config.get("http.domain").indexOf(opts.domain) === -1) {
|
||||
opts.domain = Config.get("http.domain");
|
||||
}
|
||||
|
||||
res.cookie(name, val, opts);
|
||||
}
|
||||
|
||||
|
@ -78,11 +73,7 @@ function cookieall(res, name, val, opts) {
|
|||
*/
|
||||
function redirectHttps(req, res) {
|
||||
if (!req.secure && Config.get("https.enabled")) {
|
||||
var ssldomain = Config.get("https.domain");
|
||||
var port = Config.get("https.port");
|
||||
if (port !== 443) {
|
||||
ssldomain += ":" + port;
|
||||
}
|
||||
var ssldomain = Config.get("https.full-address");
|
||||
res.redirect(ssldomain + req.path);
|
||||
return true;
|
||||
}
|
||||
|
@ -94,11 +85,7 @@ function redirectHttps(req, res) {
|
|||
*/
|
||||
function redirectHttp(req, res) {
|
||||
if (req.secure) {
|
||||
var domain = Config.get("http.domain");
|
||||
var port = Config.get("http.port");
|
||||
if (port !== 80) {
|
||||
domain += ":" + port;
|
||||
}
|
||||
var domain = Config.get("http.full-address");
|
||||
res.redirect(domain + req.path);
|
||||
return true;
|
||||
}
|
||||
|
@ -129,7 +116,7 @@ function handleChannel(req, res) {
|
|||
|
||||
var sio;
|
||||
if (req.secure) {
|
||||
sio = Config.get("https.domain") + ":" + Config.get("https.port");
|
||||
sio = Config.get("https.full-address");
|
||||
} else {
|
||||
sio = Config.get("io.domain") + ":" + Config.get("io.port");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue