AJ ONeal 2018-05-11 13:15:28 -06:00
parent d9c6a77bfc
commit 7f340412d7
1 changed files with 31 additions and 6 deletions

37
lex.js
View File

@ -24,6 +24,21 @@ module.exports.create = function (opts) {
var ports = port;
var servers = [];
function explainError(e) {
console.error('Error:' + e.message);
if ('EACCES' === e.errno) {
console.error("You don't have prmission to access '" + e.address + ":" + e.port + "'.");
console.error("You probably need to use \"sudo\" or \"sudo setcap 'cap_net_bind_service=+ep' $(which node)\"");
return;
}
if ('EADDRINUSE' === e.errno) {
console.error("'" + e.address + ":" + e.port + "' is already being used by some other program.");
console.error("You probably need to stop that program or restart your computer.");
return;
}
console.error(e.code + ": '" + e.address + ":" + e.port + "'");
}
if (!plainPorts) {
plainPorts = 80;
}
@ -37,20 +52,30 @@ module.exports.create = function (opts) {
}
plainPorts.forEach(function (p) {
promises.push(new PromiseA(function (resolve, reject) {
if (!(parseInt(p, 10) >= 0)) { console.warn("'" + p + "' doesn't seem to be a valid port number for http"); }
promises.push(new PromiseA(function (resolve) {
require('http').createServer(le.middleware(require('redirect-https')())).listen(p, function () {
console.log("Handling ACME challenges and redirecting to https on plain port " + p);
console.log("Success! Bound to port '" + p + "' to handle ACME challenges and redirect to https");
resolve();
}).on('error', reject);
}).on('error', function (e) {
console.log("Did not successfully create http server and bind to port '" + p + "':");
explainError(e);
process.exit(0);
});
}));
});
ports.forEach(function (p) {
promises.push(new PromiseA(function (resolve, reject) {
if (!(parseInt(p, 10) >= 0)) { console.warn("'" + p + "' doesn't seem to be a valid port number for https"); }
promises.push(new PromiseA(function (resolve) {
var server = require('https').createServer(le.httpsOptions, le.middleware(le.app)).listen(p, function () {
console.log("Handling ACME challenges and serving https " + p);
console.log("Success! Serving https on port '" + p + "'");
resolve();
}).on('error', reject);
}).on('error', function (e) {
console.log("Did not successfully create https server and bind to port '" + p + "':");
explainError(e);
process.exit(0);
});
servers.push(server);
}));
});