goldilocks.js/stages/01-serve.js

24 lines
567 B
JavaScript
Raw Normal View History

2016-10-07 17:23:43 +00:00
'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));
});