Email Login
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
var PromiseA;
|
||||
try {
|
||||
PromiseA = require('bluebird');
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
PromiseA = global.Promise;
|
||||
}
|
||||
|
||||
@ -31,7 +31,9 @@ module.exports.create = function (opts) {
|
||||
}
|
||||
|
||||
function _listen(plainPort, plain) {
|
||||
if (!plainPort) { plainPort = 80; }
|
||||
if (!plainPort) {
|
||||
plainPort = 80;
|
||||
}
|
||||
|
||||
var parts = String(plainPort).split(':');
|
||||
var p = parts.pop();
|
||||
@ -52,24 +54,26 @@ module.exports.create = function (opts) {
|
||||
var https;
|
||||
try {
|
||||
https = require('spdy');
|
||||
greenlock.tlsOptions.spdy = { protocols: [ 'h2', 'http/1.1' ], plain: false };
|
||||
greenlock.tlsOptions.spdy = {
|
||||
protocols: ['h2', 'http/1.1'],
|
||||
plain: false
|
||||
};
|
||||
httpType = 'http2 (spdy/h2)';
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
https = require('https');
|
||||
httpType = 'https';
|
||||
}
|
||||
server = https.createServer(
|
||||
greenlock.tlsOptions
|
||||
, greenlock.middleware.sanitizeHost(function (req, res) {
|
||||
greenlock.tlsOptions, greenlock.middleware.sanitizeHost(function (req, res) {
|
||||
try {
|
||||
greenlock.app(req, res);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.error("[error] [greenlock.app] Your HTTP handler had an uncaught error:");
|
||||
console.error(e);
|
||||
try {
|
||||
res.statusCode = 500;
|
||||
res.end("Internal Server Error: [Greenlock] HTTP exception logged for user-provided handler.");
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// ignore
|
||||
// (headers may have already been sent, etc)
|
||||
}
|
||||
@ -79,15 +83,23 @@ module.exports.create = function (opts) {
|
||||
server.type = httpType;
|
||||
}
|
||||
|
||||
if (addr) { args[1] = addr; }
|
||||
if (addr) {
|
||||
args[1] = addr;
|
||||
}
|
||||
if (!validHttpPort && !/(\/)|(\\\\)/.test(p)) {
|
||||
console.warn("'" + p + "' doesn't seem to be a valid port number, socket path, or pipe");
|
||||
}
|
||||
if (plain) { tryPlain(); } else { trySecure(); }
|
||||
if (plain) {
|
||||
tryPlain();
|
||||
} else {
|
||||
trySecure();
|
||||
}
|
||||
|
||||
var promise = new PromiseA(function (resolve) {
|
||||
args[0] = p;
|
||||
args.push(function () { resolve(server); });
|
||||
args.push(function () {
|
||||
resolve(server);
|
||||
});
|
||||
server.listen.apply(server, args).on('error', function (e) {
|
||||
if (server.listenerCount('error') < 2) {
|
||||
console.warn("Did not successfully create http server and bind to port '" + p + "':");
|
||||
@ -133,8 +145,8 @@ module.exports.create = function (opts) {
|
||||
if ('function' === typeof fnPlain) {
|
||||
fnPlain.apply(plainServer);
|
||||
} else if (!fn && !plainServer.listenerCount('listening') && !server.listenerCount('listening')) {
|
||||
console.info('[:' + (plainServer.address().port || plainServer.address())
|
||||
+ "] Handling ACME challenges and redirecting to " + server.type);
|
||||
console.info('[:' + (plainServer.address().port || plainServer.address()) +
|
||||
"] Handling ACME challenges and redirecting to " + server.type);
|
||||
}
|
||||
|
||||
// Report h2/https status
|
||||
@ -156,4 +168,4 @@ module.exports.create = function (opts) {
|
||||
};
|
||||
|
||||
return greenlock;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user