From caab061442c2bcd2928b745cce3836181b534879 Mon Sep 17 00:00:00 2001 From: Salmin Skenderovic Date: Mon, 10 Oct 2022 17:13:59 -0400 Subject: [PATCH 1/5] added proxy port the env file --- .env | 1 + 1 file changed, 1 insertion(+) diff --git a/.env b/.env index 259028a52..31310f8a5 100644 --- a/.env +++ b/.env @@ -59,6 +59,7 @@ CHAOSGENIUS_ENTERPRISE_EDITION_KEY= # System Configuration ## Frontend Configuration REACT_APP_BASE_URL= +REACT_APP_PROXY_PORT=1337 REACT_APP_DISABLE_TELEMETRY=false ## Backend Configuration From c0a5d589a0f36c02ead99e8a1ef58ca58d3b86d6 Mon Sep 17 00:00:00 2001 From: Salmin Skenderovic Date: Mon, 10 Oct 2022 17:19:16 -0400 Subject: [PATCH 2/5] added dependencies --- proxy/package.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 proxy/package.json diff --git a/proxy/package.json b/proxy/package.json new file mode 100644 index 000000000..77c7d7f15 --- /dev/null +++ b/proxy/package.json @@ -0,0 +1,17 @@ +{ + "name": "proxy", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "dotenv": "^16.0.3", + "express": "^4.18.2", + "http-proxy": "^1.18.1", + "http-proxy-middleware": "^2.0.6" + } +} \ No newline at end of file From 7363f236e4711e45bd7fbe8342df048175e1e991 Mon Sep 17 00:00:00 2001 From: Salmin Skenderovic Date: Mon, 10 Oct 2022 17:19:28 -0400 Subject: [PATCH 3/5] added proxy logic --- proxy/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 proxy/index.js diff --git a/proxy/index.js b/proxy/index.js new file mode 100644 index 000000000..906abc082 --- /dev/null +++ b/proxy/index.js @@ -0,0 +1,24 @@ +const http = require('http'); +const httpProxy = require('http-proxy'); +const path = require('path'); + +const dotenv = require('dotenv').config({ + path: path.resolve(__dirname, '../.env') +}); + +const CHAOSGENIUS_WEBAPP_URL = dotenv.parsed.CHAOSGENIUS_WEBAPP_URL +const REACT_APP_PROXY_PORT = +dotenv.parsed.REACT_APP_PROXY_PORT || 1337; + +const proxy = httpProxy.createProxyServer({}); +const server = http.createServer(function (req, res) { + if (req.url.includes('/api/')) { + // re-route all requests to the default port 8080 + proxy.web(req, res, { target: CHAOSGENIUS_WEBAPP_URL }); + } else { + // The default port for CRA npm start is 3000 + proxy.web(req, res, { target: 'http://localhost:3000' }); + } +}); + +console.log(`Listening to port ${CHAOSGENIUS_WEBAPP_URL}`); +server.listen(CHAOSGENIUS_WEBAPP_URL); From d88b30050567f2d09d4f4cfc6d717f413c4a02d1 Mon Sep 17 00:00:00 2001 From: Salmin Skenderovic Date: Mon, 10 Oct 2022 17:20:10 -0400 Subject: [PATCH 4/5] use port from env --- proxy/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/index.js b/proxy/index.js index 906abc082..1c260a46b 100644 --- a/proxy/index.js +++ b/proxy/index.js @@ -20,5 +20,5 @@ const server = http.createServer(function (req, res) { } }); -console.log(`Listening to port ${CHAOSGENIUS_WEBAPP_URL}`); -server.listen(CHAOSGENIUS_WEBAPP_URL); +console.log(`Listening to port ${REACT_APP_PROXY_PORT}`); +server.listen(REACT_APP_PROXY_PORT); From a6cdd31999ea341835036d105a89b9f20f3fd1b7 Mon Sep 17 00:00:00 2001 From: Salmin Skenderovic Date: Mon, 10 Oct 2022 17:24:32 -0400 Subject: [PATCH 5/5] added readme --- proxy/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 proxy/README.md diff --git a/proxy/README.md b/proxy/README.md new file mode 100644 index 000000000..b311b1579 --- /dev/null +++ b/proxy/README.md @@ -0,0 +1,3 @@ +For local development you can use `npm run start` on /frontend/ and forward all the api-requests to your backend. + +Set REACT_APP_PROXY_PORT=xxxx to a port you want to use during development. The main page will forward to :3000 and the API requests to the default services \ No newline at end of file