Skip to content

Load SSL cert if environment variables exist #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions packages/react-scripts/config/webpackDevServer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,35 @@
// @remove-on-eject-end
'use strict';

// ZEAL: add fs for ssl key and cert loading
const fs = require('fs');
const errorOverlayMiddleware = require('react-error-overlay/middleware');
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
const config = require('./webpack.config.dev');
const paths = require('./paths');

const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const host = process.env.HOST || '0.0.0.0';
// ZEAL: ssl file loading
const readSslFile = function(path) {
try {
return fs.readFileSync(path);
} catch (err) {
console.log('Unable to parse SSL path - ' + path);
process.exit(1);
}
};
// ZEAL: handle ssl key and certs when running http
const https = (function(https, key_path, cert_path) {
if (https === 'true') {
if (key_path && cert_path) {
return { key: readSslFile(key_path), cert: readSslFile(cert_path) };
} else {
return true;
}
} else {
return false;
}
})(process.env.HTTPS, process.env.SSL_KEY_PATH, process.env.SSL_CERT_PATH);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you're using an IIFE here. I like the way the code looks, but just curious about the decision to go this way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to call the function down below. I really wanted these methods to be in react-dev-utils and then pass in the results to this method from start.js as variable name https. Maybe that is too preemptive here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that start.js is not the only place that this config is imported, and the other importer doesn't have the necessary context, so what's here is good.


module.exports = function(proxy, allowedHost) {
return {
Expand Down Expand Up @@ -78,7 +100,8 @@ module.exports = function(proxy, allowedHost) {
ignored: /node_modules/,
},
// Enable HTTPS if the HTTPS environment variable is set to 'true'
https: protocol === 'https',
// ZEAL: load https from functions up above
https: https,
host: host,
overlay: false,
historyApiFallback: {
Expand Down