Skip to content

Commit

Permalink
Merge pull request #145 from CS3219-AY2324S1/bryan/fix-socketio-nginx
Browse files Browse the repository at this point in the history
Fix socket io namespace clash in production
  • Loading branch information
bryanlohxz authored Oct 27, 2023
2 parents 62daf81 + 5beb7d4 commit 124a206
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
export REACT_APP_QUESTIONS_SERVICE_HOST=http://peerprep.bryanlohxz.com/api/questions-service
export REACT_APP_USERS_SERVICE_HOST=http://peerprep.bryanlohxz.com/api/users-service
export REACT_APP_MATCHMAKING_SERVICE_HOST=ws://peerprep.bryanlohxz.com/api/matchmaking-service
export REACT_APP_COLLABORATION_SERVICE_HOST=ws://peerprep.bryanlohxz.com/api/collaboration-service
export REACT_APP_COLLABORATION_SERVICE_HOST=http://peerprep.bryanlohxz.com
export CI=false
yarn build
- name: Set up Git
Expand Down
5 changes: 4 additions & 1 deletion collaboration-service/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import NodeCache from "node-cache";
import { Server } from "socket.io";

const httpServer = createServer();
const io = new Server(httpServer, { cors: { origin: "*" } });
const io = new Server(httpServer, {
cors: { origin: "*" },
path: "/api/collaboration-service",
});
const roomQuestionsCache = new NodeCache();

const clientEvents = {
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
REACT_APP_QUESTIONS_SERVICE_HOST: http://localhost:3001
REACT_APP_USERS_SERVICE_HOST: http://localhost:3002
REACT_APP_MATCHMAKING_SERVICE_HOST: ws://localhost:3003
REACT_APP_COLLABORATION_SERVICE_HOST: ws://localhost:3004
REACT_APP_COLLABORATION_SERVICE_HOST: http://localhost:3004
volumes:
- ./frontend-service:/app
command: yarn start
Expand Down
5 changes: 5 additions & 0 deletions frontend-service/src/pages/Collaboration.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Collaboration = () => {
const token = window.localStorage.getItem("token");
const socket = io(`${process.env.REACT_APP_COLLABORATION_SERVICE_HOST}`, {
query: { difficulty, roomId, token },
path: "/api/collaboration-service",
});
setSocket(socket);

Expand Down Expand Up @@ -92,6 +93,10 @@ const Collaboration = () => {
socket.on("disconnect", () => {
return navigate("/matchmaking");
});

return async () => {
socket.disconnect();
};
}, [navigate, searchParams]);

useEffect(() => {
Expand Down

0 comments on commit 124a206

Please sign in to comment.