diff --git a/package-lock.json b/package-lock.json index 5477059..725b12c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,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", diff --git a/package.json b/package.json index 6ccb2bd..9954ada 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/proxy-server.js b/server/proxy-server.js index 56052c3..4337c50 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 (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}`); + }) +} +