static server updates

This commit is contained in:
AJ ONeal 2015-12-12 07:11:31 +00:00
parent d1ecac5322
commit d50f2507cf
1 changed files with 51 additions and 45 deletions

View File

@ -2,13 +2,10 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var localCerts = require('localhost.daplie.com-certificates');
var https = require('https'); var https = require('https');
var http = require('http'); var http = require('http');
var express = require('express'); var express = require('express');
var app = express(); var app = express();
var server;
var insecureServer;
var config = require('./config'); var config = require('./config');
@ -32,32 +29,10 @@ function getSecureContext(domainname, opts, cb) {
} }
//
// SSL Certificates
//
var options = {
requestCert: false
, rejectUnauthorized: true
// If you need to use SNICallback you should be using io.js >= 1.x (possibly node >= 0.12)
, SNICallback: function (domainname, cb) {
var secureContext = getSecureContext(domainname);
cb(null, secureContext);
}
// If you need to support HTTP2 this is what you need to work with
//, NPNProtocols: ['http/2.0', 'http/1.1', 'http/1.0']
//, NPNProtocols: ['http/1.1']
, key: null
, cert: null
//, ca: null
};
options.key = localCerts.key;
options.cert = localCerts.cert;
// log the requests // log the requests
app.use('/', function (req, res, next) { app.use('/', function (req, res, next) {
console.log(req.method + ' ' + req.headers['host'], req.protocol + req.url); console.log('[' + req.ip + ']', req.method + ' ' + req.headers.host, req.protocol + req.url);
next();
}); });
// handle static requests to /.well-known/acme-challenge // handle static requests to /.well-known/acme-challenge
app.use( app.use(
@ -66,22 +41,53 @@ app.use(
); );
// Start the tls sni server function serveHttps() {
server = https.createServer(options); //
server.on('error', function (err) { // SSL Certificates
console.error(err); //
}); var server;
server.listen(config.tlsSni01Port, function () { var localCerts = require('localhost.daplie.com-certificates');
console.log('Listening'); var options = {
}); requestCert: false
server.on('request', app); , rejectUnauthorized: true
// Start the http server // If you need to use SNICallback you should be using io.js >= 1.x (possibly node >= 0.12)
insecureServer = http.createServer(); , SNICallback: function (domainname, cb) {
insecureServer.on('error', function (err) { var secureContext = getSecureContext(domainname);
console.error(err); cb(null, secureContext);
}); }
insecureServer.listen(config.http01Port, function () { // If you need to support HTTP2 this is what you need to work with
console.log('Listening'); //, NPNProtocols: ['http/2.0', 'http/1.1', 'http/1.0']
}); //, NPNProtocols: ['http/1.1']
insecureServer.on('request', app); , key: localCerts.key
, cert: localCerts.cert
//, ca: null
};
// Start the tls sni server4
server = https.createServer(options);
server.on('error', function (err) {
console.error(err);
});
server.on('request', app);
server.listen(config.tlsSni01Port, function () {
console.log('[https] Listening', server.address());
});
}
function serveHttp() {
// Start the http server4
var insecureServer = http.createServer();
insecureServer.on('error', function (err) {
console.error(err);
});
// note that request handler must be attached *before* and handle comes in
insecureServer.on('request', app);
insecureServer.listen(config.http01Port, function () {
console.log('[http] Listening', insecureServer.address());
});
}
serveHttps();
serveHttp();