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 path = require('path');
var localCerts = require('localhost.daplie.com-certificates');
var https = require('https');
var http = require('http');
var express = require('express');
var app = express();
var server;
var insecureServer;
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
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
app.use(
@ -66,22 +41,53 @@ app.use(
);
// Start the tls sni server
server = https.createServer(options);
server.on('error', function (err) {
console.error(err);
});
server.listen(config.tlsSni01Port, function () {
console.log('Listening');
});
server.on('request', app);
function serveHttps() {
//
// SSL Certificates
//
var server;
var localCerts = require('localhost.daplie.com-certificates');
var options = {
requestCert: false
, rejectUnauthorized: true
// Start the http server
insecureServer = http.createServer();
insecureServer.on('error', function (err) {
// 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: localCerts.key
, cert: localCerts.cert
//, ca: null
};
// Start the tls sni server4
server = https.createServer(options);
server.on('error', function (err) {
console.error(err);
});
insecureServer.listen(config.http01Port, function () {
console.log('Listening');
});
insecureServer.on('request', app);
});
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();