diff --git a/client/package-lock.json b/client/package-lock.json index 92f6328..ea63efd 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -15,6 +15,7 @@ "@types/node": "^16.11.36", "@types/react": "^18.0.9", "@types/react-dom": "^18.0.4", + "http-proxy-middleware": "^2.0.6", "react": "^18.1.0", "react-dom": "^18.1.0", "react-router-dom": "^6.3.0", diff --git a/client/package.json b/client/package.json index 865da73..0a7d2f5 100644 --- a/client/package.json +++ b/client/package.json @@ -10,6 +10,7 @@ "@types/node": "^16.11.36", "@types/react": "^18.0.9", "@types/react-dom": "^18.0.4", + "http-proxy-middleware": "^2.0.6", "react": "^18.1.0", "react-dom": "^18.1.0", "react-router-dom": "^6.3.0", diff --git a/client/src/pages/Maps.tsx b/client/src/pages/Maps.tsx index 3330119..d435f99 100644 --- a/client/src/pages/Maps.tsx +++ b/client/src/pages/Maps.tsx @@ -12,7 +12,7 @@ function Maps() { useEffect(() => { const fetchData = async () => { const res = await fetch( - `${process.env.REACT_APP_SERVER_URL}/api/v1/maps` + `/api/v1/maps` ); const data = await res.json(); setData(data.rows as Map[]); @@ -42,7 +42,7 @@ function Maps() { {`${value.owner.firstName} ${value.owner.lastName}`}

{value.name} diff --git a/client/src/pages/Plugins.tsx b/client/src/pages/Plugins.tsx index 6ec6f1a..e4590d3 100644 --- a/client/src/pages/Plugins.tsx +++ b/client/src/pages/Plugins.tsx @@ -11,7 +11,7 @@ function Plugins() { useEffect(() => { const fetchData = async () => { const res = await fetch( - `${process.env.REACT_APP_SERVER_URL}/api/v1/plugins` + `/api/v1/plugins` ); const data = await res.json(); setData(data.rows as Plugin[]); @@ -51,7 +51,7 @@ function Plugins() {

{value.name} diff --git a/client/src/pages/Simulations.tsx b/client/src/pages/Simulations.tsx index 019e587..d3bf9c9 100644 --- a/client/src/pages/Simulations.tsx +++ b/client/src/pages/Simulations.tsx @@ -3,13 +3,13 @@ import Layout from "../components/Layout"; function Simulations() { const onStopSimulation = () => { - fetch(`${process.env.REACT_APP_SERVER_URL}/api/v1/clusters/stop`); + fetch(`/api/v1/clusters/stop`); }; const onDisconnectSimulator = () => { - fetch(`${process.env.REACT_APP_SERVER_URL}/api/v1/clusters/disconnect`); + fetch(`/api/v1/clusters/disconnect`); }; const onStartSimulation = () => { - fetch(`${process.env.REACT_APP_SERVER_URL}/api/v1/clusters/start/apiOnly`); + fetch(`/api/v1/clusters/start/apiOnly`); }; return ( diff --git a/client/src/pages/Vehicle/VehiclePage.tsx b/client/src/pages/Vehicle/VehiclePage.tsx index 34cf659..f987531 100644 --- a/client/src/pages/Vehicle/VehiclePage.tsx +++ b/client/src/pages/Vehicle/VehiclePage.tsx @@ -13,7 +13,7 @@ function VehiclePage() { useEffect(() => { const fetchData = async () => { const res = await fetch( - `${process.env.REACT_APP_SERVER_URL}/api/v1${location.pathname}` + `/api/v1${location.pathname}` ); const data = await res.json(); setVehicle(data as Vehicle); @@ -64,7 +64,7 @@ function VehiclePage() {

diff --git a/client/src/pages/Vehicle/Vehicles.tsx b/client/src/pages/Vehicle/Vehicles.tsx index acf58de..d1356c6 100644 --- a/client/src/pages/Vehicle/Vehicles.tsx +++ b/client/src/pages/Vehicle/Vehicles.tsx @@ -13,7 +13,7 @@ function Vehicles() { useEffect(() => { const fetchData = async () => { const res = await fetch( - `${process.env.REACT_APP_SERVER_URL}/api/v1/vehicles` + `/api/v1/vehicles` ); const data = await res.json(); setData(data.rows as Vehicle[]); @@ -46,7 +46,7 @@ function Vehicles() { {`${value.owner.firstName} ${value.owner.lastName}`}

{value.name} diff --git a/client/src/setupProxy.js b/client/src/setupProxy.js new file mode 100644 index 0000000..2e7b80b --- /dev/null +++ b/client/src/setupProxy.js @@ -0,0 +1,11 @@ +const { createProxyMiddleware } = require('http-proxy-middleware'); + +module.exports = function(app) { + app.use( + '/', + createProxyMiddleware({ + target: process.env.REACT_APP_SERVER_URL, + changeOrigin: true, + }) + ); +};