Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Chore/add-proxy #1151

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions proxy/README.md
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions proxy/index.js
Original file line number Diff line number Diff line change
@@ -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 ${REACT_APP_PROXY_PORT}`);
server.listen(REACT_APP_PROXY_PORT);
17 changes: 17 additions & 0 deletions proxy/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}