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,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 // SSL Certificates
// //
var server;
var localCerts = require('localhost.daplie.com-certificates');
var options = { var options = {
requestCert: false requestCert: false
, rejectUnauthorized: true , rejectUnauthorized: true
@ -47,41 +59,35 @@ var options = {
// If you need to support HTTP2 this is what you need to work with // 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/2.0', 'http/1.1', 'http/1.0']
//, NPNProtocols: ['http/1.1'] //, NPNProtocols: ['http/1.1']
, key: null , key: localCerts.key
, cert: null , cert: localCerts.cert
//, ca: null //, ca: null
}; };
options.key = localCerts.key;
options.cert = localCerts.cert;
// Start the tls sni server4
// 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
server = https.createServer(options); server = https.createServer(options);
server.on('error', function (err) { server.on('error', function (err) {
console.error(err); console.error(err);
}); });
server.listen(config.tlsSni01Port, function () {
console.log('Listening');
});
server.on('request', app); server.on('request', app);
server.listen(config.tlsSni01Port, function () {
console.log('[https] Listening', server.address());
});
}
// Start the http server function serveHttp() {
insecureServer = http.createServer(); // Start the http server4
var insecureServer = http.createServer();
insecureServer.on('error', function (err) { insecureServer.on('error', function (err) {
console.error(err); console.error(err);
}); });
insecureServer.listen(config.http01Port, function () { // note that request handler must be attached *before* and handle comes in
console.log('Listening');
});
insecureServer.on('request', app); insecureServer.on('request', app);
insecureServer.listen(config.http01Port, function () {
console.log('[http] Listening', insecureServer.address());
});
}
serveHttps();
serveHttp();