diff --git a/package-lock.json b/package-lock.json index aba0cd7..2e47fb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,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", diff --git a/package.json b/package.json index 0a00dfd..6888af1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/proxy-server.js b/server/proxy-server.js index 56052c3..a841242 100644 --- a/server/proxy-server.js +++ b/server/proxy-server.js @@ -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}`); + }) +} +