merge
This commit is contained in:
commit
e081f59686
14
serve.js
14
serve.js
|
@ -92,6 +92,9 @@ function createServer(port, pubdir, content, opts) {
|
|||
|
||||
var directive = { public: pubdir, content: content, livereload: opts.livereload
|
||||
, servername: opts.servername, expressApp: opts.expressApp };
|
||||
var redirectApp = require('redirect-https')({
|
||||
port: port
|
||||
});
|
||||
|
||||
// returns an instance of node-letsencrypt with additional helper methods
|
||||
var webrootPath = require('os').tmpdir();
|
||||
|
@ -159,13 +162,7 @@ function createServer(port, pubdir, content, opts) {
|
|||
server.on('request', function (req, res) {
|
||||
console.log('[' + req.method + '] ' + req.url);
|
||||
if (!req.socket.encrypted) {
|
||||
res.statusCode = 301;
|
||||
res.setHeader(
|
||||
'Location'
|
||||
, 'https://' + (req.headers.host || 'localhost')
|
||||
+ (httpsPort === opts.port ? '' : ':' + opts.port)
|
||||
);
|
||||
res.end();
|
||||
redirectApp(req, res);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -197,7 +194,8 @@ function run() {
|
|||
var tls = require('tls');
|
||||
|
||||
// letsencrypt
|
||||
var cert = require('localhost.daplie.com-certificates');
|
||||
var cert = require('localhost.daplie.com-certificates').merge({});
|
||||
|
||||
var opts = {
|
||||
agreeTos: argv.agreeTos || argv['agree-tos']
|
||||
, debug: argv.debug
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
var https = require('httpolyglot');
|
||||
var httpsOptions = require('localhost.daplie.com-certificates').merge({});
|
||||
var httpsPort = 8443;
|
||||
var redirectApp = require('redirect-https')({
|
||||
port: httpsPort
|
||||
});
|
||||
|
||||
var server = https.createServer(httpsOptions);
|
||||
|
||||
server.on('request', function (req, res) {
|
||||
if (!req.socket.encrypted) {
|
||||
redirectApp(req, res);
|
||||
return;
|
||||
}
|
||||
|
||||
res.end("Hello, Encrypted World!");
|
||||
});
|
||||
|
||||
server.listen(httpsPort, function () {
|
||||
console.log('https://' + 'localhost.daplie.com' + (443 === httpsPort ? ':' : ':' + httpsPort));
|
||||
});
|
Loading…
Reference in New Issue