diff --git a/boot/master.js b/boot/master.js index 8bdfc27..7a97b83 100644 --- a/boot/master.js +++ b/boot/master.js @@ -63,6 +63,7 @@ var info = { , trustProxy: useCaddy ? true : false , lexConf: letsencrypt , varpath: path.join(__dirname, '..', '..', 'var') + , etcpath: path.join(__dirname, '..', '..', 'etc') } }; diff --git a/boot/worker.js b/boot/worker.js index 45dd6c5..8a599fb 100644 --- a/boot/worker.js +++ b/boot/worker.js @@ -46,6 +46,9 @@ module.exports.create = function (opts) { function walkLe(domainname) { var PromiseA = require('bluebird'); + if (!domainname) { + return PromiseA.reject(new Error('no domainname given for walkLe')); + } var fs = PromiseA.promisifyAll(require('fs')); var path = require('path'); var parts = domainname.split('.'); //.replace(/^www\./, '').split('.'); diff --git a/install.sh b/install.sh index 25934bf..4eb6c3d 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,8 @@ #!/bin/bash -sudo mkdir -p /srv/walnut/{certs,core,letsencrypt,lib,config} +sudo mkdir -p /srv/walnut/{certs,core,letsencrypt,lib,etc,config} +sudo mkdir -p /srv/walnut/etc/org.oauth3.consumer +sudo mkdir -p /srv/walnut/etc/org.oauth3.provider sudo mkdir -p /srv/walnut/packages/{api,pages,services} sudo chown -R $(whoami):$(whoami) /srv/walnut diff --git a/lib/apis.js b/lib/apis.js index a9dcaee..24c1263 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -186,7 +186,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { // // TODO handle /accounts/:accountId // - return PromiseA.resolve(require(apipath).create({}/*pkgConf*/, deps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) { + return PromiseA.resolve(require(apipath).create({ + etcpath: xconfx.etcpath + }/*pkgConf*/, deps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) { localCache.pkgs[apiId] = { pkg: pkg, handler: handler || myApp, createdAt: Date.now() }; localCache.pkgs[apiId].handler(req, res, next); }); diff --git a/lib/main.js b/lib/main.js index febe97c..ae14a8e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -87,6 +87,16 @@ module.exports.create = function (app, xconfx, apiFactories, apiDeps) { localCache.le[req.hostname] = { conf: leAuth, createdAt: Date.now() }; redirectHttps(req, res); + }, function (err) { + console.error('[Error] lib/main.js walkLe'); + if (err.stack) { + console.error(err.stack); + } + else { + console.error(new Error('getstack').stack); + console.error(err); + } + res.send({ error: { message: "failed to get tls certificate for '" + (req.hostname || '') + "'" } }); }); } diff --git a/lib/worker.js b/lib/worker.js index 08cc48c..2c606d6 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -89,7 +89,7 @@ module.exports.create = function (webserver, xconfx, state) { // helpers , allAsync: function () { - return memstore.allASync().then(function (db) { + return memstore.allAsync().then(function (db) { return Object.keys(db).filter(function (key) { return 0 === key.indexOf(scope); }).map(function (key) { @@ -98,14 +98,14 @@ module.exports.create = function (webserver, xconfx, state) { }); } , lengthAsync: function () { - return memstore.allASync().then(function (db) { + return memstore.allAsync().then(function (db) { return Object.keys(db).filter(function (key) { return 0 === key.indexOf(scope); }).length; }); } , clearAsync: function () { - return memstore.allASync().then(function (db) { + return memstore.allAsync().then(function (db) { return Object.keys(db).filter(function (key) { return 0 === key.indexOf(scope); }).map(function (key) { @@ -145,8 +145,16 @@ module.exports.create = function (webserver, xconfx, state) { , systemSqlFactory: systemFactory }; + var hostsmap = {}; function log(req, res, next) { - console.log('[worker/log]', req.method, req.headers.host, req.url); + var hostname = (req.hostname || req.headers.host || '').split(':').shift(); + console.log('[worker/log]', req.method, hostname, req.url); + if (hostname && !hostsmap[hostname]) { + hostsmap[hostname] = true; + require('fs').writeFile( + require('path').join(__dirname, '..', '..', 'var', 'hostnames', hostname) + , hostname, function () {}); + } next(); } diff --git a/package.json b/package.json index d29ba9e..43b765b 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "app-scoped-ids": "^1.0.1", "authcodes": "git://github.com/Daplie/authcodes.git", "authenticator": "^1.0.0", - "bluebird": "2.x", + "bluebird": "3.x", "body-parser": "1.x", "btoa": "1.x", "bytes": "^1.0.0", @@ -75,6 +75,7 @@ "finalhandler": "^0.3.4", "foreachasync": "5.x", "fresh": "^0.2.4", + "http2": "^3.3.2", "human-readable-ids": "1.x", "inherits": "^2.0.1", "ipify": "^1.0.5",