more generalizing of configs
This commit is contained in:
parent
134d294cf5
commit
384f465ff1
|
@ -25,7 +25,8 @@ var conf = {
|
||||||
, locked: false // TODO XXX
|
, locked: false // TODO XXX
|
||||||
, ipcKey: null
|
, ipcKey: null
|
||||||
, caddyfilepath: config.caddy.conf
|
, caddyfilepath: config.caddy.conf
|
||||||
, sitespath: path.join(__dirname, '..', '..', 'sites-enabled')
|
// TODO needs mappings from db
|
||||||
|
, caddy: config.caddy
|
||||||
};
|
};
|
||||||
var state = {};
|
var state = {};
|
||||||
var caddy;
|
var caddy;
|
||||||
|
@ -43,7 +44,7 @@ function fork() {
|
||||||
cluster.on('online', function (worker) {
|
cluster.on('online', function (worker) {
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
// TODO XXX Should these be configurable? If so, where?
|
// TODO XXX Should these be configurable? If so, where?
|
||||||
var certPaths = [path.join(__dirname, '..', '..', 'certs', 'live')];
|
var certPaths = config.certPaths;
|
||||||
var info;
|
var info;
|
||||||
conf.ddns = config.ddns;
|
conf.ddns = config.ddns;
|
||||||
conf.redirects = config.redirects;
|
conf.redirects = config.redirects;
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
function tplCaddyfile(conf) {
|
function tplCaddyfile(conf) {
|
||||||
var contents = [];
|
var contents = [];
|
||||||
|
|
||||||
conf.domains.forEach(function (hostname) {
|
conf.caddy.domains.forEach(function (hostname) {
|
||||||
var content = "";
|
var content = "";
|
||||||
|
var pagesname = hostname;
|
||||||
|
|
||||||
// TODO prefix
|
// TODO prefix
|
||||||
content+= "https://" + hostname + " {\n"
|
content+= "https://" + hostname + " {\n"
|
||||||
|
@ -17,7 +18,7 @@ function tplCaddyfile(conf) {
|
||||||
if (conf.locked) {
|
if (conf.locked) {
|
||||||
content += " root /srv/walnut/init.public/\n";
|
content += " root /srv/walnut/init.public/\n";
|
||||||
} else {
|
} else {
|
||||||
content += " root /srv/walnut/sites-enabled/" + hostname + "/\n";
|
content += " root " + conf.caddy.sitespath + "/" + pagesname + "/\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
content +=
|
content +=
|
||||||
|
@ -38,15 +39,18 @@ function tplCaddyfile(conf) {
|
||||||
module.exports.tplCaddyfile = tplCaddyfile;
|
module.exports.tplCaddyfile = tplCaddyfile;
|
||||||
module.exports.create = function (config) {
|
module.exports.create = function (config) {
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var caddypath = config.caddypath;
|
var caddyBin = config.caddy.bin;
|
||||||
var caddyfilepath = config.caddyfilepath;
|
var caddyConf = config.caddy.conf;
|
||||||
var sitespath = config.sitespath;
|
// TODO put up a booting / lock screen on boot
|
||||||
|
// and wait for all to be grabbed from db
|
||||||
|
// NOTE caddy cannot yet support multiple roots
|
||||||
|
// (needed for example.com/appname instead of appname.example.com)
|
||||||
var caddy;
|
var caddy;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
// TODO this should be expanded to include proxies a la proxydyn
|
// TODO this should be expanded to include proxies a la proxydyn
|
||||||
function writeCaddyfile(conf, cb) {
|
function writeCaddyfile(conf, cb) {
|
||||||
fs.readdir(sitespath, function (err, nodes) {
|
fs.readdir(config.caddy.sitespath, function (err, nodes) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(err);
|
cb(err);
|
||||||
|
@ -57,12 +61,12 @@ module.exports.create = function (config) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.domains = nodes.filter(function (node) {
|
conf.caddy.domains = nodes.filter(function (node) {
|
||||||
return /\./.test(node) && !/(^\.)|([\/\:\\])/.test(node);
|
return /\./.test(node) && !/(^\.)|([\/\:\\])/.test(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
var contents = tplCaddyfile(conf);
|
var contents = tplCaddyfile(conf);
|
||||||
fs.writeFile(caddyfilepath, contents, 'utf8', function (err) {
|
fs.writeFile(caddyConf, contents, 'utf8', function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(err);
|
cb(err);
|
||||||
|
@ -104,7 +108,7 @@ module.exports.create = function (config) {
|
||||||
// Command failed: killall caddy
|
// Command failed: killall caddy
|
||||||
// caddy: no process found
|
// caddy: no process found
|
||||||
}
|
}
|
||||||
caddy = spawn(caddypath, ['-conf', caddyfilepath], { stdio: ['ignore', 'pipe', 'pipe'] });
|
caddy = spawn(caddyBin, ['-conf', caddyConf], { stdio: ['ignore', 'pipe', 'pipe'] });
|
||||||
caddy.stdout.on('data', function (str) {
|
caddy.stdout.on('data', function (str) {
|
||||||
console.error('[Caddy]', str.toString('utf8'));
|
console.error('[Caddy]', str.toString('utf8'));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue