Skip to content

Commit

Permalink
Merge pull request #12 from KOREAN139/fix/proxy
Browse files Browse the repository at this point in the history
Use proxy to use api from server
  • Loading branch information
YuqiHuai authored Jun 30, 2022
2 parents 25e0799 + a07cfe8 commit 00a2148
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Maps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand Down Expand Up @@ -42,7 +42,7 @@ function Maps() {
<span className="absolute top-5 left-5 text-white text-lg font-medium">{`${value.owner.firstName} ${value.owner.lastName}`}</span>
<img
className="w-full rounded"
src={`${process.env.REACT_APP_SERVER_URL}${value.imageUrl}?type=small`}
src={`${value.imageUrl}?type=small`}
/>
<p className="text-lg font-semibold mt-2 truncate">
{value.name}
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand Down Expand Up @@ -51,7 +51,7 @@ function Plugins() {

<img
className="w-full rounded"
src={`${process.env.REACT_APP_SERVER_URL}${value.imageUrl}?type=small`}
src={`${value.imageUrl}?type=small`}
/>
<p className="text-lg font-semibold mt-2 truncate">
{value.name}
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/Simulations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Vehicle/VehiclePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -64,7 +64,7 @@ function VehiclePage() {
</div>
<div>
<img
src={`${process.env.REACT_APP_SERVER_URL}${vehicle.imageUrl}`}
src={`${vehicle.imageUrl}`}
/>
</div>
<div>
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Vehicle/Vehicles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand Down Expand Up @@ -46,7 +46,7 @@ function Vehicles() {
<span className="absolute top-5 left-5 text-white text-lg font-medium">{`${value.owner.firstName} ${value.owner.lastName}`}</span>
<img
className="w-full rounded"
src={`${process.env.REACT_APP_SERVER_URL}${value.imageUrl}?type=small`}
src={`${value.imageUrl}?type=small`}
/>
<p className="text-lg font-semibold mt-2 truncate">
{value.name}
Expand Down
11 changes: 11 additions & 0 deletions client/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -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,
})
);
};

0 comments on commit 00a2148

Please sign in to comment.