Skip to content

Commit

Permalink
Use HTTPS in local development
Browse files Browse the repository at this point in the history
- Install `selfsigned`.
- Run the proxy server with a self-signed certificate in local development.
  • Loading branch information
eatyourgreens committed Feb 13, 2023
1 parent 41a4a5d commit e8c5bef
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 @@ -38,6 +38,7 @@
"file-loader": "^6.2.0",
"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 (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 e8c5bef

Please sign in to comment.