From ec0026c53b0637e51f5f94ef0055c581512b3b6a Mon Sep 17 00:00:00 2001 From: dmbch Date: Thu, 25 Jan 2018 22:34:48 +0100 Subject: [PATCH] feat(express): implement SSL support SSL support is now implemented independently of webpack dev server --- packages/express/lib/utils.js | 20 ++++++++++++++++++- .../ssl/localhost.ssl.crt | 0 .../ssl/localhost.ssl.key | 0 .../{build-config => express}/ssl/rootca.pem | 0 4 files changed, 19 insertions(+), 1 deletion(-) rename packages/{build-config => express}/ssl/localhost.ssl.crt (100%) rename packages/{build-config => express}/ssl/localhost.ssl.key (100%) rename packages/{build-config => express}/ssl/rootca.pem (100%) diff --git a/packages/express/lib/utils.js b/packages/express/lib/utils.js index 688b740c0..9a9222815 100644 --- a/packages/express/lib/utils.js +++ b/packages/express/lib/utils.js @@ -1,6 +1,10 @@ 'use strict'; +var fs = require('fs'); var url = require('url'); +var path = require('path'); +var http = require('http'); +var https = require('https'); var hopsConfig = require('hops-config'); @@ -22,7 +26,21 @@ function defaultCallback(error) { } exports.run = function run(app, callback) { - var server = app.listen(hopsConfig.port, hopsConfig.host, function(error) { + var server; + if (hopsConfig.https) { + var options = { + key: fs.readFileSync( + hopsConfig.keyFile || path.join(__dirname, 'ssl', 'localhost.ssl.key') + ), + cert: fs.readFileSync( + hopsConfig.certFile || path.join(__dirname, 'ssl', 'localhost.ssl.crt') + ), + }; + server = https.createServer(options, app); + } else { + server = http.createServer(app); + } + server.listen(hopsConfig.port, hopsConfig.host, function(error) { (callback || defaultCallback)(error, server); }); }; diff --git a/packages/build-config/ssl/localhost.ssl.crt b/packages/express/ssl/localhost.ssl.crt similarity index 100% rename from packages/build-config/ssl/localhost.ssl.crt rename to packages/express/ssl/localhost.ssl.crt diff --git a/packages/build-config/ssl/localhost.ssl.key b/packages/express/ssl/localhost.ssl.key similarity index 100% rename from packages/build-config/ssl/localhost.ssl.key rename to packages/express/ssl/localhost.ssl.key diff --git a/packages/build-config/ssl/rootca.pem b/packages/express/ssl/rootca.pem similarity index 100% rename from packages/build-config/ssl/rootca.pem rename to packages/express/ssl/rootca.pem