feat(frontend): add support for environment variable NODE_ENV in start script

feat(frontend): change proxy to backend container name
feat(chatModal): add support for environment variable NODE_ENV in WebSocket connection
This commit is contained in:
Gabriel Almeida 2023-04-27 10:16:28 -03:00
commit 1e8f342037
2 changed files with 10 additions and 3 deletions

View file

@ -39,7 +39,7 @@
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"start": "NODE_ENV=development react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
@ -62,5 +62,5 @@
"last 1 safari version"
]
},
"proxy": "http://127.0.0.1:5003"
"proxy": "http://backend:7860"
}

View file

@ -55,7 +55,14 @@ export default function ChatModal({
};
function connectWS() {
const newWs = new WebSocket(`ws://127.0.0.1:7860/chat/${flow.id}`);
// Check if the app is running with npm start or npm run build
// if npm start, use localhost, otherwise use the windows.location.host
const urlWs =
process.env.NODE_ENV === "development"
? `ws://localhost:7860/chat/${flow.id}`
: `wss://${window.location.host}/chat/${flow.id}`;
const newWs = new WebSocket(urlWs);
newWs.onopen = () => {
console.log("WebSocket connection established!");
};