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,9 +29,24 @@ function getSecureContext(domainname, opts, cb) {
}
// log the requests
app.use('/', function (req, res, next) {
console.log('[' + req.ip + ']', req.method + ' ' + req.headers.host, req.protocol + req.url);
next();
});
// handle static requests to /.well-known/acme-challenge
app.use(
'/.well-known/acme-challenge'
, express.static(path.join(__dirname, 'acme-challenge'), { dotfiles: undefined })
);
function serveHttps() {
//
// SSL Certificates
//
var server;
var localCerts = require('localhost.daplie.com-certificates');
var options = {
requestCert: false
, rejectUnauthorized: true
@ -47,41 +59,35 @@ var options = {
// 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
, key: localCerts.key
, cert: localCerts.cert
//, 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);
});
// handle static requests to /.well-known/acme-challenge
app.use(
'/.well-known/acme-challenge'
, express.static(path.join(__dirname, 'acme-challenge'), { dotfiles: undefined })
);
// Start the tls sni server
// Start the tls sni server4
server = https.createServer(options);
server.on('error', function (err) {
console.error(err);
});
server.listen(config.tlsSni01Port, function () {
console.log('Listening');
});
server.on('request', app);
server.listen(config.tlsSni01Port, function () {
console.log('[https] Listening', server.address());
});
}
// Start the http server
insecureServer = http.createServer();
function serveHttp() {
// Start the http server4
var insecureServer = http.createServer();
insecureServer.on('error', function (err) {
console.error(err);
});
insecureServer.listen(config.http01Port, function () {
console.log('Listening');
});
// 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();