Skip to content

Commit

Permalink
Use HTTPS in local development (#106)
Browse files Browse the repository at this point in the history
* Use HTTPS in local development
- Install `selfsigned`.
- Run the proxy server with a self-signed certificate in local development.

* Fix NODE_ENV variable

---------

Co-authored-by: Shaun A. Noordin <[email protected]>
  • Loading branch information
eatyourgreens and shaunanoordin authored Feb 13, 2023
1 parent b423075 commit a84e06f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"css-loader": "^6.7.3",
"sass": "^1.58.0",
"sass-loader": "^13.2.0",
"selfsigned": "^2.1.1",
"style-loader": "^3.3.1",
"url": "^0.11.0",
"webpack": "^5.75.0",
Expand Down
30 changes: 23 additions & 7 deletions server/proxy-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,26 @@ function proxyGet (req, res) {

server.get('*', proxyGet)

server.listen(config.port, (err) => {
if (err) throw err
console.log(`Proxy Server running at port ${config.port}`)
console.log(`Acceptable origins: ${config.origins.split(';')}`)
console.log(`Acceptable targets: ${config.targets.split(';')}`)
console.log(`MS ML URL: ${config.url_for_msml}`)
})
if (process.env.NODE_ENV === 'production') {
server.listen(config.port, (err) => {
if (err) throw err
console.log(`Proxy Server running at port ${config.port}`)
console.log(`Acceptable origins: ${config.origins.split(';')}`)
console.log(`Acceptable targets: ${config.targets.split(';')}`)
console.log(`MS ML URL: ${config.url_for_msml}`)
})
} else {
const https = require('https');
const selfsigned = require('selfsigned');
const attrs = [{ name: 'commonName', value: 'local.zooniverse.org' }];
const { cert, private: key } = selfsigned.generate(attrs, { days: 365 });
https.createServer({ cert, key }, server)
.listen(config.port, (err) => {
if (err) throw err;
console.log(`Proxy Server running at port ${config.port}`);
console.log(`Acceptable origins: ${config.origins.split(';')}`);
console.log(`Acceptable targets: ${config.targets.split(';')}`);
console.log(`MS ML URL: ${config.url_for_msml}`);
})
}

0 comments on commit a84e06f

Please sign in to comment.