lazy loading bugfix

This commit is contained in:
AJ ONeal 2015-02-19 20:51:17 +00:00
parent 8c4687bd23
commit d5a7ab6049
2 changed files with 23 additions and 19 deletions

View File

@ -56,21 +56,6 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
var domainMergeMap = {}; var domainMergeMap = {};
var domainMerged = []; var domainMerged = [];
function loadDummyCerts() {
var certs = {
key: fs.readFileSync(path.join(certsPath, 'server', 'dummy-server.key.pem'))
, cert: fs.readFileSync(path.join(certsPath, 'server', 'dummy-server.crt.pem'))
, ca: fs.readdirSync(path.join(certsPath, 'ca')).filter(function (node) {
return /crt\.pem$/.test(node);
}).map(function (node) {
console.log('[Add CA]', node);
return fs.readFileSync(path.join(certsPath, 'ca', node));
})
};
return certs
}
dummyCerts = loadDummyCerts();
function createSecureContext(certs) { function createSecureContext(certs) {
// workaround for v0.12 / v1.2 backwards compat // workaround for v0.12 / v1.2 backwards compat
try { try {
@ -79,7 +64,14 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
return require('crypto').createCredentials(certs).context; return require('crypto').createCredentials(certs).context;
} }
} }
secureContexts.dummy = createSecureContext(dummyCerts);
function getDummyAppContext(err, msg) {
console.error(err);
console.error(msg);
return function (req, res) {
res.end('{ "error": { "message": "' + msg + '" } }');
}
}
function getAppContext(domaininfo) { function getAppContext(domaininfo) {
var localApp; var localApp;
@ -123,10 +115,10 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
return fs.readFileSync(path.join(certsPath, 'ca', node)); return fs.readFileSync(path.join(certsPath, 'ca', node));
}) })
}; };
secureContexts.dummy = crypto.createCredentials(certs).context; secureContexts.dummy = createSecureContext(dummyCerts);
dummyCerts = certs; dummyCerts = certs;
return certs
} }
loadDummyCerts();
function loadCerts(domainname) { function loadCerts(domainname) {
// TODO make async // TODO make async
@ -230,6 +222,8 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
function runServer() { function runServer() {
//provide a SNICallback when you create the options for the https server //provide a SNICallback when you create the options for the https server
loadDummyCerts();
secureOpts = { secureOpts = {
// fallback / default dummy certs // fallback / default dummy certs
key: dummyCerts.key key: dummyCerts.key
@ -245,7 +239,7 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
var secureContext = secureContexts[domainname] var secureContext = secureContexts[domainname]
|| loadCerts(domainname) || loadCerts(domainname)
|| secureContexts.dummy || secureContexts.dummy
//|| createSecureContext(dummyCerts) || createSecureContext(dummyCerts)
//|| createSecureContext(loadDummyCerts()) //|| createSecureContext(loadDummyCerts())
; ;

View File

@ -38,16 +38,26 @@
"homepage": "https://github.com/Daplie/walnut", "homepage": "https://github.com/Daplie/walnut",
"dependencies": { "dependencies": {
"bluebird": "^2.9.9", "bluebird": "^2.9.9",
"body-parser": "^1.12.0",
"check-ip-address": "^1.1.0", "check-ip-address": "^1.1.0",
"cli": "^0.6.5", "cli": "^0.6.5",
"compression": "^1.4.1",
"connect": "^3.3.4", "connect": "^3.3.4",
"connect-cors": "^0.5.6",
"connect-query": "^0.2.0",
"cookie-parser": "^1.3.4",
"errorhandler": "^1.3.4",
"escape-string-regexp": "^1.0.2", "escape-string-regexp": "^1.0.2",
"express": "^4.11.2", "express": "^4.11.2",
"express-session": "^1.10.3",
"foreachasync": "^5.0.5", "foreachasync": "^5.0.5",
"human-readable-ids": "^1.0.1",
"nat-pmp": "0.0.3", "nat-pmp": "0.0.3",
"node-acme": "0.0.1", "node-acme": "0.0.1",
"request": "^2.53.0", "request": "^2.53.0",
"serve-static": "^1.9.1",
"ssl-root-cas": "^1.1.7", "ssl-root-cas": "^1.1.7",
"urlrouter": "^0.5.4",
"vhost": "^3.0.0", "vhost": "^3.0.0",
"xml2js": "^0.4.5" "xml2js": "^0.4.5"
} }