Skip to content

Commit 19f46db

Browse files
author
Kevin Craine
committed
Load SSL cert if environment variables exist
1 parent 5bd5892 commit 19f46db

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

packages/react-scripts/config/webpackDevServer.config.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,35 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13+
// ZEAL: add fs for ssl key and cert loading
14+
const fs = require('fs');
1315
const errorOverlayMiddleware = require('react-error-overlay/middleware');
1416
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
1517
const config = require('./webpack.config.dev');
1618
const paths = require('./paths');
1719

18-
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
1920
const host = process.env.HOST || '0.0.0.0';
21+
// ZEAL: ssl file loading
22+
const readSslFile = function(path) {
23+
try {
24+
return fs.readFileSync(path);
25+
} catch (err) {
26+
console.log('Unable to parse SSL path - ' + path);
27+
process.exit(1);
28+
}
29+
};
30+
// ZEAL: handle ssl key and certs when running http
31+
const https = (function(https, key_path, cert_path) {
32+
if (https === 'true') {
33+
if (key_path && cert_path) {
34+
return { key: readSslFile(key_path), cert: readSslFile(cert_path) };
35+
} else {
36+
return true;
37+
}
38+
} else {
39+
return false;
40+
}
41+
})(process.env.HTTPS, process.env.SSL_KEY_PATH, process.env.SSL_CERT_PATH);
2042

2143
module.exports = function(proxy, allowedHost) {
2244
return {
@@ -78,7 +100,8 @@ module.exports = function(proxy, allowedHost) {
78100
ignored: /node_modules/,
79101
},
80102
// Enable HTTPS if the HTTPS environment variable is set to 'true'
81-
https: protocol === 'https',
103+
// ZEAL: load https from functions up above
104+
https: https,
82105
host: host,
83106
overlay: false,
84107
historyApiFallback: {

0 commit comments

Comments
 (0)