Skip to content

Commit

Permalink
feat : ws 에러 수정 완료 및 소켓 통신 nginx로 변경 성공
Browse files Browse the repository at this point in the history
  • Loading branch information
minseok128 committed Aug 25, 2024
1 parent 596da1f commit ec7e663
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
35 changes: 18 additions & 17 deletions frontend/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { initializeRouter, createRoutes } from "./core/router.js";
import { initializeRouter, createRoutes, changeUrl } from "./core/router.js";
import { getCookie } from "./core/jwt.js";


class App {
app;
lan;
Expand All @@ -16,21 +17,21 @@ export const root = new App();
export const routes = createRoutes(root);

const online = () => {
const onlineSocket = new WebSocket(
'ws://'
+ "localhost:8000"
+ '/ws/online/'
);
console.log(onlineSocket);
onlineSocket.onopen = () => {
const token = getCookie("jwt");
onlineSocket.send(JSON.stringify({ 'action': 'authenticate', 'token': token }));
};
onlineSocket.onclose = () => {
console.log("close");
// 로그아웃
};
}
const onlineSocket = new WebSocket(
'wss://'
+ "localhost:443"
+ '/ws/online/'
);
console.log(onlineSocket);
onlineSocket.onopen = () => {
const token = getCookie("jwt");
onlineSocket.send(JSON.stringify({ 'action': 'authenticate', 'token': token }));
};
onlineSocket.onclose = () => {
console.log("online socket closed");
changeUrl("/404", false);
};
}
initializeRouter(routes);
online();
4 changes: 2 additions & 2 deletions frontend/src/components/Game-Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class GameCore extends Component {
initState() {
this.keysPressed = {};
this.gameSocket = this.gameSocket = new WebSocket(
'ws://'
+ "localhost:8000"
'wss://'
+ "localhost:443"
+ '/ws/game/'
+ this.props.uid
+ '/'
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/Main-Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ export class Menu extends Component {
});

this.addEvent('click', '#LocalGame', () => {
const uid = "145058";
changeUrl(`/game/local/${uid}`);
changeUrl(`/game/local/${this.uid}`);
});

this.addEvent('click', "#MultiGame", () => {
Expand Down
18 changes: 7 additions & 11 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { defineConfig } from "vite";

export default defineConfig({
server: {
host: "0.0.0.0",
port: 5173,
proxy: {
"/api": {
// TEST: 평가 시 80번 포트로 변경 (nginx를 거쳐 api를 호출하도록)
target: "https://localhost:443",
changeOrigin: true,
},
},
server: {
host: "0.0.0.0",
hmr: {
clientPort: 5173,
protocol: "ws",
},
});
},
});
12 changes: 12 additions & 0 deletions nginx/compose.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /ws/ {
proxy_pass http://backend:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
12 changes: 12 additions & 0 deletions nginx/local.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /ws/ {
proxy_pass http://host.docker.internal:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}

0 comments on commit ec7e663

Please sign in to comment.