update redirect

This commit is contained in:
AJ ONeal 2016-10-07 11:23:43 -06:00
parent 7f2bca2fd9
commit f69bbb3d66
2 changed files with 28 additions and 8 deletions

View File

@ -58,6 +58,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
});
server.on('error', function (err) {
if (opts.errorPort || opts.manualPort) {
@ -95,13 +98,7 @@ function createServer(port, pubdir, content, opts) {
server.on('request', function (req, res) {
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;
}
@ -270,7 +267,7 @@ function run() {
return promise.then(function (matchingIps) {
if (matchingIps) {
if (!matchingIps.length) {
console.log("Neither the attached nor external interfaces match '" + argv.servername + "'");
console.info("Neither the attached nor external interfaces match '" + argv.servername + "'");
}
}
opts.matchingIps = matchingIps || [];

23
stages/01-serve.js Normal file
View File

@ -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));
});