diff --git a/.gitignore b/.gitignore index d11b3f9b..7363a552 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,9 @@ jspm_packages # VScode workspace settings .vscode/ static/dll.vendor.js -dll \ No newline at end of file +dll + +# SSL cert stuff +webpack_config/server.key +webpack_config/server.crt +webpack_config/server.csr diff --git a/README.md b/README.md index f358d9ab..c8864f91 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,16 @@ It generates app in `dist` folder. npm run test # run tests with Jest ``` +#### Dev (HTTPS): + +1. Create your own SSL Certificate (Heroku has a [nice guide here](https://devcenter.heroku.com/articles/ssl-certificate-self)) +2. Move the `.key` and `.crt` files into `webpack_config/server.*` +3. Run the following command: + +```bash +npm run dev:https +``` + #### Derivation Check: ##### The derivation checker utility assumes that you have: 1. Docker installed/available @@ -28,7 +38,7 @@ npm run test # run tests with Jest ##### Docker setup instructions: 1. Install docker (on macOS, I suggest [Docker for Mac](https://docs.docker.com/docker-for-mac/)) 2. `docker pull dternyak/eth-priv-to-addr` - + ##### Run Derivation Checker ```bash npm run derivation-checker diff --git a/package.json b/package.json index 7498826b..543e7ac0 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,8 @@ "pretest": "check-node-version --package", "dev": "node webpack_config/server.js", "predev": "check-node-version --package", + "dev:https": "HTTPS=true node webpack_config/server.js", + "predev:https": "check-node-version --package", "flow": "flow", "derivation-checker": "babel-node common/derivation-checker.js --presets es2015,stage-0,flow", "postinstall": "webpack --config=./webpack_config/webpack.dll.js", @@ -116,9 +118,6 @@ "precommit": "lint-staged" }, "lint-staged": { - "*.{js,jsx}": [ - "prettier --write --single-quote", - "git add" - ] + "*.{js,jsx}": ["prettier --write --single-quote", "git add"] } } diff --git a/webpack_config/config.js b/webpack_config/config.js index 413c0643..ed13e948 100644 --- a/webpack_config/config.js +++ b/webpack_config/config.js @@ -2,7 +2,7 @@ const path = require('path'); module.exports = { - port: 3000, + port: process.env.HTTPS ? 3443 : 3000, title: 'MEW', publicPath: process.env.BUILD_GH_PAGES ? '/react-semantic.ui-starter/' : '/', srcPath: path.join(__dirname, './../common'), diff --git a/webpack_config/log-plugin.js b/webpack_config/log-plugin.js index c43df1b9..767ee564 100644 --- a/webpack_config/log-plugin.js +++ b/webpack_config/log-plugin.js @@ -8,9 +8,12 @@ module.exports = class LogPlugin { } apply(compiler) { + const protocol = process.env.HTTPS ? 'https' : 'http'; compiler.plugin('done', () => { console.log( - `> App is running at ${chalk.yellow(`http://localhost:${this.port}`)}\n` + `> App is running at ${chalk.yellow( + `${protocol}://localhost:${this.port}` + )}\n` ); }); } diff --git a/webpack_config/server.js b/webpack_config/server.js index fbb9525c..e750f648 100644 --- a/webpack_config/server.js +++ b/webpack_config/server.js @@ -2,6 +2,8 @@ const path = require('path'); const express = require('express'); const webpack = require('webpack'); +const https = require('https'); +const fs = require('fs'); const webpackConfig = require('./webpack.dev'); const config = require('./config'); const LogPlugin = require('./log-plugin'); @@ -60,4 +62,26 @@ app.get('*', (req, res) => { }); }); -app.listen(port); +if (process.env.HTTPS) { + let creds = {}; + try { + creds.key = fs.readFileSync(path.resolve(__dirname, 'server.key'), 'utf8'); + } catch (err) { + console.error('Failed to get SSL private key at webpack_config/server.key'); + console.error(err); + process.exit(1); + } + + try { + creds.cert = fs.readFileSync(path.resolve(__dirname, 'server.crt'), 'utf8'); + } catch (err) { + console.error('Failed to get SSL certificate at webpack_config/server.crt'); + console.error(err); + process.exit(1); + } + + const httpsApp = https.createServer(creds, app); + httpsApp.listen(port); +} else { + app.listen(port); +}