From 0921cfa54c68f30c3781f78c7cd525f3ab379d92 Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 16:47:24 +0200 Subject: [PATCH 01/11] fix typos --- readme.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index ff4260c..5572703 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,7 @@ +--- +lang: en-GB +--- + # The game ## General principle La traque is a IRL team game where the goal is to catch another team without being catched by another team. @@ -63,10 +67,10 @@ https://example.com:3000 ``` ## Deployment -Put your certificate and private key in the proxy/ssl folder. They need to be named `cert.pem` and `privkey.pem`. -You can then depploy the docker application with `docker compose up`. +Put your certificate and private key in the `proxy/ssl` folder. They need to be named `cert.pem` and `privkey.pem`. +You can then deploy the docker application with `docker compose up`. -You can change the production environment varialbes for the backend in the docker-compose.yml file. The frontend environment variables can be changed in the .env file in the traque-front directory. +You can change the production environment variables for the backend in the `docker-compose.yml` file. The frontend environment variables can be changed in the `.env` file in the `traque-front` directory. # Authors - [Quentin Roussel](mailto:quentin.roussel11@gmail.com) (initial version) \ No newline at end of file From b3619c738087004f8f4eb4cdb3c72f7984ff604c Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 16:56:47 +0200 Subject: [PATCH 02/11] suppression reverse proxy (pour utiliser celui de rezel), maj node et netoyage --- docker-compose.yaml | 11 ++--------- traque-back/Dockerfile | 4 ++-- traque-front/Dockerfile | 22 ++++++---------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 1e85fec..743ee0a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,15 +1,8 @@ services: front: - build: ./traque-front - restart: always - - reverse_proxy: - build: ./proxy ports: - - "3000:443" - volumes: - # reusing the ssl files from the backend - - ./traque-back/ssl:/etc/nginx/ssl:ro + - "3000:3000" + build: ./traque-front restart: always back: diff --git a/traque-back/Dockerfile b/traque-back/Dockerfile index b7966f7..1463db3 100644 --- a/traque-back/Dockerfile +++ b/traque-back/Dockerfile @@ -1,5 +1,5 @@ -# Use Node 16 alpine as parent image -FROM node:16-alpine +# Use Node 20 alpine as parent image +FROM node:20-alpine # Change the working directory on the Docker image to /app WORKDIR /app diff --git a/traque-front/Dockerfile b/traque-front/Dockerfile index 3d1b852..f5f63d2 100644 --- a/traque-front/Dockerfile +++ b/traque-front/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine AS base +FROM node:20-alpine AS base # Install dependencies only when needed FROM base AS deps @@ -7,13 +7,8 @@ RUN apk add --no-cache libc6-compat WORKDIR /app # Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm ci; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ - else echo "Lockfile not found." && exit 1; \ - fi +COPY package.json package-lock.json* ./ +RUN npm ci # Rebuild the source code only when needed @@ -25,14 +20,9 @@ COPY . . # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry # Uncomment the following line in case you want to disable telemetry during the build. -# ENV NEXT_TELEMETRY_DISABLED 1 +ENV NEXT_TELEMETRY_DISABLED 1 -RUN \ - if [ -f yarn.lock ]; then yarn run build; \ - elif [ -f package-lock.json ]; then npm run build; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ - else echo "Lockfile not found." && exit 1; \ - fi +RUN npm run build # Production image, copy all the files and run next FROM base AS runner @@ -40,7 +30,7 @@ WORKDIR /app ENV NODE_ENV production # Uncomment the following line in case you want to disable telemetry during runtime. -# ENV NEXT_TELEMETRY_DISABLED 1 +ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs From 78530c7a3890477a548a8aa106156656ee3cdac8 Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 16:57:30 +0200 Subject: [PATCH 03/11] maj deps --- traque-back/package-lock.json | 24 ++++++++++----------- traque-front/package-lock.json | 38 +++++++++++++++++----------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/traque-back/package-lock.json b/traque-back/package-lock.json index 4642d51..56ec0c6 100644 --- a/traque-back/package-lock.json +++ b/traque-back/package-lock.json @@ -287,9 +287,9 @@ } }, "node_modules/engine.io": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz", - "integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==", + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.5.tgz", + "integrity": "sha512-C5Pn8Wk+1vKBoHghJODM63yk8MvrO9EWZUfkAt5HAqIgPE4/8FF0PEGHXtEd40l223+cE5ABWuPzm38PHFXfMA==", "dependencies": { "@types/cookie": "^0.4.1", "@types/cors": "^2.8.12", @@ -300,7 +300,7 @@ "cors": "~2.8.5", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0" + "ws": "~8.17.1" }, "engines": { "node": ">=10.2.0" @@ -931,12 +931,12 @@ } }, "node_modules/socket.io-adapter": { - "version": "2.5.4", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.4.tgz", - "integrity": "sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz", + "integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==", "dependencies": { "debug": "~4.3.4", - "ws": "~8.11.0" + "ws": "~8.17.1" } }, "node_modules/socket.io-parser": { @@ -1040,15 +1040,15 @@ } }, "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { diff --git a/traque-front/package-lock.json b/traque-front/package-lock.json index c48a574..cd72f3d 100644 --- a/traque-front/package-lock.json +++ b/traque-front/package-lock.json @@ -1019,12 +1019,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -1435,14 +1435,14 @@ "dev": true }, "node_modules/engine.io-client": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.3.tgz", - "integrity": "sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.4.tgz", + "integrity": "sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==", "dependencies": { "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0", + "ws": "~8.17.1", "xmlhttprequest-ssl": "~2.0.0" } }, @@ -2126,9 +2126,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" @@ -3202,12 +3202,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -5111,15 +5111,15 @@ "dev": true }, "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { From cf96ea45d7c3fc9b2678c18b97b99e44fe1ebdfb Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 16:58:09 +0200 Subject: [PATCH 04/11] redirection de / vers /team --- traque-front/next.config.mjs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/traque-front/next.config.mjs b/traque-front/next.config.mjs index 7ea2c19..f75af37 100644 --- a/traque-front/next.config.mjs +++ b/traque-front/next.config.mjs @@ -1,8 +1,20 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - experimental: { - outputStandalone: true - } + + output: 'standalone', + + async redirects() { + return [ + { + source: '/', + destination: '/team', + permanent: true, + }, + ] + }, + }; + + export default nextConfig; From d6cf0e8d60cd3e9fae18fb234261186cb1814390 Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 17:00:50 +0200 Subject: [PATCH 05/11] suppression reverse proxy --- proxy/Dockerfile | 8 -------- proxy/nginx.conf | 42 ------------------------------------------ 2 files changed, 50 deletions(-) delete mode 100644 proxy/Dockerfile delete mode 100644 proxy/nginx.conf diff --git a/proxy/Dockerfile b/proxy/Dockerfile deleted file mode 100644 index 3772885..0000000 --- a/proxy/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -# nginx/Dockerfile - -FROM nginx:1.23.3-alpine - -COPY nginx.conf /etc/nginx/nginx.conf - -EXPOSE 80 -EXPOSE 443 diff --git a/proxy/nginx.conf b/proxy/nginx.conf deleted file mode 100644 index eb5699f..0000000 --- a/proxy/nginx.conf +++ /dev/null @@ -1,42 +0,0 @@ -# nginx/nginx.conf - -events { -} - -http { - upstream front { - server front:3000; - } - server { - # Redirect HTTP requests to HTTPS. - listen 80; - server_name localhost; - root /srv/public; - return 301 https://$host$request_uri; - } - - server { - listen 443 ssl; - - server_name localhost; - root /srv/public; - server_tokens off; - - ssl_certificate /etc/nginx/ssl/cert.pem; - ssl_certificate_key /etc/nginx/ssl/privkey.pem; - - location / { - try_files $uri $uri/ @front; - } - - location @front { - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_set_header X-Forwarded-Ssl on; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://front; - proxy_cookie_path / "/; HTTPOnly; Secure"; - } - } -} \ No newline at end of file From f0285e2873bcfd3df68b052ccc15a8a4bbc75437 Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 17:01:26 +0200 Subject: [PATCH 06/11] formatage --- traque-back/admin_socket.js | 14 +++++++------- traque-back/game.js | 12 ++++++------ traque-back/penalty_controller.js | 2 +- traque-back/team_socket.js | 10 +++++----- traque-back/zone_manager.js | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/traque-back/admin_socket.js b/traque-back/admin_socket.js index ffdf7a7..f7f2420 100644 --- a/traque-back/admin_socket.js +++ b/traque-back/admin_socket.js @@ -20,9 +20,9 @@ const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD; * @param {String} data The data to send */ export function secureAdminBroadcast(event, data) { - loggedInSockets.forEach(s => { - io.of("admin").to(s).emit(event, data); - }); + loggedInSockets.forEach(s => { + io.of("admin").to(s).emit(event, data); + }); } //Array of logged in sockets @@ -73,10 +73,10 @@ export function initAdminSocketHandler() { socket.emit("error", "Not logged in"); return; } - if(!game.changeSettings(settings)) { + if (!game.changeSettings(settings)) { socket.emit("error", "Invalid settings"); } - secureAdminBroadcast("game_settings",game.settings); + secureAdminBroadcast("game_settings", game.settings); playersBroadcast("game_settings", game.settings); }) @@ -99,10 +99,10 @@ export function initAdminSocketHandler() { socket.emit("error", "Not logged in"); return; } - if(!penaltyController.updateSettings(settings)) { + if (!penaltyController.updateSettings(settings)) { socket.emit("error", "Invalid settings"); socket.emit("penalty_settings", penaltyController.settings) - }else { + } else { secureAdminBroadcast("penalty_settings", penaltyController.settings) } diff --git a/traque-back/game.js b/traque-back/game.js index 9078d65..c0260f9 100644 --- a/traque-back/game.js +++ b/traque-back/game.js @@ -20,11 +20,11 @@ export const GameState = { export default { //List of teams, as objects. To see the fields see the addTeam methods - teams : [], + teams: [], //Current state of the game - state : GameState.SETUP, + state: GameState.SETUP, //Settings of the game - settings : { + settings: { loserEndGameMessage: "", winnerEndGameMessage: "", capturedMessage: "", @@ -37,7 +37,7 @@ export default { * @returns true if the settings are applied */ changeSettings(newSettings) { - this.settings = {...this.settings, ...newSettings}; + this.settings = { ...this.settings, ...newSettings }; return true; }, @@ -232,7 +232,7 @@ export default { } //The location sent by the team will be null if the browser call API dooes not succeed //See issue #19 - if(location == null) { + if (location == null) { return false; } team.currentLocation = location; @@ -264,7 +264,7 @@ export default { if (team == undefined) { return false; } - if(team.currentLocation == null) { + if (team.currentLocation == null) { return false; } diff --git a/traque-back/penalty_controller.js b/traque-back/penalty_controller.js index 2304518..695f0eb 100644 --- a/traque-back/penalty_controller.js +++ b/traque-back/penalty_controller.js @@ -4,7 +4,7 @@ This module manages the verification of the game rules and the penalties. import { isInCircle } from "./map_utils.js"; import { sendUpdatedTeamInformations, teamBroadcast } from "./team_socket.js"; import { secureAdminBroadcast } from "./admin_socket.js"; -import game, {GameState} from "./game.js"; +import game, { GameState } from "./game.js"; import zone from "./zone_manager.js"; export default { diff --git a/traque-back/team_socket.js b/traque-back/team_socket.js index 80b520e..b8ef61f 100644 --- a/traque-back/team_socket.js +++ b/traque-back/team_socket.js @@ -4,7 +4,7 @@ It receives messages, checks permissions, manages authentication and performs ac This module also exposes functions to send messages via socket to all teams */ import { secureAdminBroadcast } from "./admin_socket.js"; -import { io} from "./index.js"; +import { io } from "./index.js"; import game from "./game.js"; import zone from "./zone_manager.js"; @@ -43,7 +43,7 @@ function logoutPlayer(id) { export function sendUpdatedTeamInformations(teamId) { let team = game.getTeam(teamId) - if(!team) { + if (!team) { return false; } team.sockets.forEach(socketId => { @@ -106,7 +106,7 @@ export function initTeamSocket() { return; } let team = game.getTeam(teamId) - if(team == undefined) { + if (team == undefined) { logoutPlayer(socket.id); return; } @@ -125,8 +125,8 @@ export function initTeamSocket() { return; } game.updateTeamChasing(); - teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation,locationSendDeadline: team.locationSendDeadline }); - teamBroadcast(teamId,"success", "Position udpated") + teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation, locationSendDeadline: team.locationSendDeadline }); + teamBroadcast(teamId, "success", "Position udpated") secureAdminBroadcast("teams", game.teams) }); diff --git a/traque-back/zone_manager.js b/traque-back/zone_manager.js index 45c9039..e2e8203 100644 --- a/traque-back/zone_manager.js +++ b/traque-back/zone_manager.js @@ -200,8 +200,8 @@ export default { onNextZoneUpdate(newZone) { playersBroadcast("new_zone", newZone) secureAdminBroadcast("new_zone", newZone) - }, - + }, + //a call to onZoneUpdate will be made every updateIntervalSeconds when the zone is changing onZoneUpdate(zone) { playersBroadcast("zone", zone) From e42a24d4d29e98aa9a9378c57f39d9bcfa3a6a63 Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 23:09:10 +0200 Subject: [PATCH 07/11] maj nextjs --- traque-front/package-lock.json | 112 ++++++++++++++++++--------------- traque-front/package.json | 2 +- 2 files changed, 62 insertions(+), 52 deletions(-) diff --git a/traque-front/package-lock.json b/traque-front/package-lock.json index cd72f3d..cf459af 100644 --- a/traque-front/package-lock.json +++ b/traque-front/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@hello-pangea/dnd": "^16.6.0", "leaflet-defaulticon-compatibility": "^0.1.2", - "next": "14.1.4", + "next": "^14.2.9", "react": "^18", "react-dom": "^18", "react-leaflet": "^4.2.1", @@ -256,9 +256,9 @@ } }, "node_modules/@next/env": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.1.4.tgz", - "integrity": "sha512-e7X7bbn3Z6DWnDi75UWn+REgAbLEqxI8Tq2pkFOFAMpWAWApz/YCUhtWMWn410h8Q2fYiYL7Yg5OlxMOCfFjJQ==" + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.9.tgz", + "integrity": "sha512-hnDAoDPMii31V0ivibI8p6b023jOF1XblWTVjsDUoZKwnZlaBtJFZKDwFqi22R8r9i6W08dThUWU7Bsh2Rg8Ww==" }, "node_modules/@next/eslint-plugin-next": { "version": "14.1.4", @@ -270,9 +270,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.1.4.tgz", - "integrity": "sha512-ubmUkbmW65nIAOmoxT1IROZdmmJMmdYvXIe8211send9ZYJu+SqxSnJM4TrPj9wmL6g9Atvj0S/2cFmMSS99jg==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.9.tgz", + "integrity": "sha512-/kfQifl3uLYi3DlwFlzCkgxe6fprJNLzzTUFknq3M5wGYicDIbdGlxUl6oHpVLJpBB/CBY3Y//gO6alz/K4NWA==", "cpu": [ "arm64" ], @@ -285,9 +285,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.1.4.tgz", - "integrity": "sha512-b0Xo1ELj3u7IkZWAKcJPJEhBop117U78l70nfoQGo4xUSvv0PJSTaV4U9xQBLvZlnjsYkc8RwQN1HoH/oQmLlQ==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.9.tgz", + "integrity": "sha512-tK/RyhCmOCiXQ9IVdFrBbZOf4/1+0RSuJkebXU2uMEsusS51TjIJO4l8ZmEijH9gZa0pJClvmApRHi7JuBqsRw==", "cpu": [ "x64" ], @@ -300,9 +300,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.1.4.tgz", - "integrity": "sha512-457G0hcLrdYA/u1O2XkRMsDKId5VKe3uKPvrKVOyuARa6nXrdhJOOYU9hkKKyQTMru1B8qEP78IAhf/1XnVqKA==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.9.tgz", + "integrity": "sha512-tS5eqwsp2nO7mzywRUuFYmefNZsUKM/mTG3exK2jIHv9TEVklE1SByB1KMhFkqlit1PxS9YK1tV8BOV90Wpbrw==", "cpu": [ "arm64" ], @@ -315,9 +315,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.1.4.tgz", - "integrity": "sha512-l/kMG+z6MB+fKA9KdtyprkTQ1ihlJcBh66cf0HvqGP+rXBbOXX0dpJatjZbHeunvEHoBBS69GYQG5ry78JMy3g==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.9.tgz", + "integrity": "sha512-8svpeTFNAMTUMKQbEzE8qRAwl9o7mNBv7LR1bmSkQvo1oy4WrNyZbhWsldOiKrc4mZ5dfQkGYsI9T75mIFMfeA==", "cpu": [ "arm64" ], @@ -330,9 +330,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.1.4.tgz", - "integrity": "sha512-BapIFZ3ZRnvQ1uWbmqEGJuPT9cgLwvKtxhK/L2t4QYO7l+/DxXuIGjvp1x8rvfa/x1FFSsipERZK70pewbtJtw==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.9.tgz", + "integrity": "sha512-0HNulLWpKTB7H5BhHCkEhcRAnWUHeAYCftrrGw3QC18+ZywTdAoPv/zEqKy/0adqt+ks4JDdlgSQ1lNKOKjo0A==", "cpu": [ "x64" ], @@ -345,9 +345,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.1.4.tgz", - "integrity": "sha512-mqVxTwk4XuBl49qn2A5UmzFImoL1iLm0KQQwtdRJRKl21ylQwwGCxJtIYo2rbfkZHoSKlh/YgztY0qH3wG1xIg==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.9.tgz", + "integrity": "sha512-hhVFViPHLAVUJRNtwwm609p9ozWajOmRvzOZzzKXgiVGwx/CALxlMUeh+M+e0Zj6orENhWLZeilOPHpptuENsA==", "cpu": [ "x64" ], @@ -360,9 +360,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.1.4.tgz", - "integrity": "sha512-xzxF4ErcumXjO2Pvg/wVGrtr9QQJLk3IyQX1ddAC/fi6/5jZCZ9xpuL9Tzc4KPWMFq8GGWFVDMshZOdHGdkvag==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.9.tgz", + "integrity": "sha512-p/v6XlOdrk06xfN9z4evLNBqftVQUWiyduQczCwSj7hNh8fWTbzdVxsEiNOcajMXJbQiaX/ZzZdFgKVmmJnnGQ==", "cpu": [ "arm64" ], @@ -375,9 +375,9 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.1.4.tgz", - "integrity": "sha512-WZiz8OdbkpRw6/IU/lredZWKKZopUMhcI2F+XiMAcPja0uZYdMTZQRoQ0WZcvinn9xZAidimE7tN9W5v9Yyfyw==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.9.tgz", + "integrity": "sha512-IcW9dynWDjMK/0M05E3zopbRen7v0/yEaMZbHFOSS1J/w+8YG3jKywOGZWNp/eCUVtUUXs0PW+7Lpz8uLu+KQA==", "cpu": [ "ia32" ], @@ -390,9 +390,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.1.4.tgz", - "integrity": "sha512-4Rto21sPfw555sZ/XNLqfxDUNeLhNYGO2dlPqsnuCg8N8a2a9u1ltqBOPQ4vj1Gf7eJC0W2hHG2eYUHuiXgY2w==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.9.tgz", + "integrity": "sha512-gcbpoXyWZdVOBgNa5BRzynrL5UR1nb2ZT38yKgnphYU9UHjeecnylMHntrQiMg/QtONDcJPFC/PmsS47xIRYoA==", "cpu": [ "x64" ], @@ -470,11 +470,17 @@ "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.1.tgz", "integrity": "sha512-dzJtaDAAoXx4GCOJpbB2eG/Qj8VDpdwkLsWGzGm+0L7E8/434RyMbAHmk9ubXWVAb9nXmc44jUf8GKqVDiKezg==" }, + "node_modules/@swc/counter": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", + "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==" + }, "node_modules/@swc/helpers": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.2.tgz", - "integrity": "sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz", + "integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==", "dependencies": { + "@swc/counter": "^0.1.3", "tslib": "^2.4.0" } }, @@ -3284,12 +3290,12 @@ "dev": true }, "node_modules/next": { - "version": "14.1.4", - "resolved": "https://registry.npmjs.org/next/-/next-14.1.4.tgz", - "integrity": "sha512-1WTaXeSrUwlz/XcnhGTY7+8eiaFvdet5z9u3V2jb+Ek1vFo0VhHKSAIJvDWfQpttWjnyw14kBeq28TPq7bTeEQ==", + "version": "14.2.9", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.9.tgz", + "integrity": "sha512-3CzBNo6BuJnRjcQvRw+irnU1WiuJNZEp+dkzkt91y4jeIDN/Emg95F+takSYiLpJ/HkxClVQRyqiTwYce5IVqw==", "dependencies": { - "@next/env": "14.1.4", - "@swc/helpers": "0.5.2", + "@next/env": "14.2.9", + "@swc/helpers": "0.5.5", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "graceful-fs": "^4.2.11", @@ -3303,18 +3309,19 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.1.4", - "@next/swc-darwin-x64": "14.1.4", - "@next/swc-linux-arm64-gnu": "14.1.4", - "@next/swc-linux-arm64-musl": "14.1.4", - "@next/swc-linux-x64-gnu": "14.1.4", - "@next/swc-linux-x64-musl": "14.1.4", - "@next/swc-win32-arm64-msvc": "14.1.4", - "@next/swc-win32-ia32-msvc": "14.1.4", - "@next/swc-win32-x64-msvc": "14.1.4" + "@next/swc-darwin-arm64": "14.2.9", + "@next/swc-darwin-x64": "14.2.9", + "@next/swc-linux-arm64-gnu": "14.2.9", + "@next/swc-linux-arm64-musl": "14.2.9", + "@next/swc-linux-x64-gnu": "14.2.9", + "@next/swc-linux-x64-musl": "14.2.9", + "@next/swc-win32-arm64-msvc": "14.2.9", + "@next/swc-win32-ia32-msvc": "14.2.9", + "@next/swc-win32-x64-msvc": "14.2.9" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", + "@playwright/test": "^1.41.2", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.3.0" @@ -3323,6 +3330,9 @@ "@opentelemetry/api": { "optional": true }, + "@playwright/test": { + "optional": true + }, "sass": { "optional": true } @@ -4725,9 +4735,9 @@ } }, "node_modules/tslib": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", - "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" }, "node_modules/type-check": { "version": "0.4.0", diff --git a/traque-front/package.json b/traque-front/package.json index 2c2f124..14e78cb 100644 --- a/traque-front/package.json +++ b/traque-front/package.json @@ -12,7 +12,7 @@ "dependencies": { "@hello-pangea/dnd": "^16.6.0", "leaflet-defaulticon-compatibility": "^0.1.2", - "next": "14.1.4", + "next": "^14.2.9", "react": "^18", "react-dom": "^18", "react-leaflet": "^4.2.1", From 7c2f02188dd603b16ec5690649d7da7126a8a82a Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 23:09:30 +0200 Subject: [PATCH 08/11] formattage --- traque-front/app/admin/page.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/traque-front/app/admin/page.js b/traque-front/app/admin/page.js index af4a7d7..a12197e 100644 --- a/traque-front/app/admin/page.js +++ b/traque-front/app/admin/page.js @@ -25,12 +25,12 @@ export default function AdminPage() {

Game state

Current : {gameState}
- changeState(GameState.SETUP)}>Reset game - changeState(GameState.PLACEMENT)}>Start placement - changeState(GameState.PLAYING)}>Start game + changeState(GameState.SETUP)}>Reset game + changeState(GameState.PLACEMENT)}>Start placement + changeState(GameState.PLAYING)}>Start game
- + {gameState == GameState.PLACEMENT &&
} {(gameState == GameState.SETUP || gameState == GameState.PLACEMENT) && } From 284dccb702da32bfb01209dadb84fa8a66d8fbdd Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Mon, 9 Sep 2024 23:11:10 +0200 Subject: [PATCH 09/11] front: msg avertissement si zones invalides creees (issue #23) --- traque-front/components/admin/mapPicker.jsx | 29 ++++++++++++------- .../components/admin/zoneSelector.jsx | 4 +-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/traque-front/components/admin/mapPicker.jsx b/traque-front/components/admin/mapPicker.jsx index e511c3b..c9d7993 100644 --- a/traque-front/components/admin/mapPicker.jsx +++ b/traque-front/components/admin/mapPicker.jsx @@ -80,17 +80,26 @@ export function ZonePicker({ minZone, setMinZone, maxZone, setMaxZone, editMode, minHover(e); } } + return ( - - - {minCenter && minRadius && } - {maxCenter && maxRadius && } - - - +
+
+ + + {minCenter && minRadius && } + {maxCenter && maxRadius && } + + + +
+ { maxCenter && minCenter && typeof maxCenter.distanceTo === 'function' + && maxRadius + maxCenter.distanceTo(minCenter) >= minRadius + &&

La zone de fin doit être incluse dans celle de départ

} +
+ ) } diff --git a/traque-front/components/admin/zoneSelector.jsx b/traque-front/components/admin/zoneSelector.jsx index 2ef1781..5b00205 100644 --- a/traque-front/components/admin/zoneSelector.jsx +++ b/traque-front/components/admin/zoneSelector.jsx @@ -41,9 +41,7 @@ export function ZoneSelector() {

Edit zones

{editMode == EditMode.MIN && setEditMode(EditMode.MAX)}>Edit end zone} {editMode == EditMode.MAX && setEditMode(EditMode.MIN)}>Edit start zone} -
- -
+

Number of reductions

setReductionCount(e.target.value)}> From 0f2d0dc86ae9c0b63068eae6ffc2c0ea177542a0 Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Tue, 10 Sep 2024 17:37:41 +0200 Subject: [PATCH 10/11] back: fix #23 --- traque-back/game.js | 9 +++++++++ traque-back/util.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/traque-back/game.js b/traque-back/game.js index c0260f9..7a7b6d1 100644 --- a/traque-back/game.js +++ b/traque-back/game.js @@ -8,6 +8,8 @@ import { playersBroadcast, sendUpdatedTeamInformations } from "./team_socket.js" import penaltyController from "./penalty_controller.js"; import zoneManager from "./zone_manager.js"; +import { getDistanceFromLatLon } from "./map_utils.js"; + /** * The possible states of the game */ @@ -329,6 +331,13 @@ export default { if (this.state == GameState.PLAYING || this.state == GameState.FINISHED) { return false; } + var min = newSettings.min; + var max = newSettings.max; + // The end zone must be included in the start zone + var dist = getDistanceFromLatLon(min.center, max.center); + if (min.radius + dist >= max.radius) { + return false; + } return zoneManager.udpateSettings(newSettings) }, diff --git a/traque-back/util.js b/traque-back/util.js index 1699761..4c7cb75 100644 --- a/traque-back/util.js +++ b/traque-back/util.js @@ -10,4 +10,4 @@ */ export function map(value, oldMin, oldMax, newMin, newMax) { return ((value - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin; -} \ No newline at end of file +} From 616f42880dfbd7d9417384b5c18107695e4e710b Mon Sep 17 00:00:00 2001 From: Mathieu Oriol Date: Sun, 15 Sep 2024 17:21:31 +0200 Subject: [PATCH 11/11] deploiement: reverse proxy nginx pour rediriger les requetes au front ou back suivant url --- docker-compose.yaml | 15 +++++------ proxy/Dockerfile | 7 +++++ proxy/nginx.conf | 26 +++++++++++++++++++ traque-back/index.js | 15 +++++------ traque-front/components/admin/teamEdit.jsx | 9 +++++-- .../components/team/enemyTeamModal.jsx | 7 ++++- .../components/team/waitingScreen.jsx | 7 ++++- traque-front/context/socketContext.jsx | 15 ++++++++--- 8 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 proxy/Dockerfile create mode 100644 proxy/nginx.conf diff --git a/docker-compose.yaml b/docker-compose.yaml index 743ee0a..0d8bbd5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,19 +1,18 @@ services: - front: + reverse_proxy: + build: ./proxy ports: - - "3000:3000" + - "80:80" + restart: always + + front: build: ./traque-front restart: always back: build: ./traque-back - ports: - - "3001:3001" restart: always environment: ADMIN_PASSWORD: 'traquebdsbanger' HOST: '0.0.0.0' - PORT: 3001 - #Those files need to exist in traque-back/ssl for https to work - SSL_KEY: "ssl/privkey.pem" - SSL_CERT: "ssl/cert.pem" \ No newline at end of file + PORT: 3001 \ No newline at end of file diff --git a/proxy/Dockerfile b/proxy/Dockerfile new file mode 100644 index 0000000..16e670c --- /dev/null +++ b/proxy/Dockerfile @@ -0,0 +1,7 @@ +# nginx/Dockerfile + +FROM nginx:alpine + +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 80 diff --git a/proxy/nginx.conf b/proxy/nginx.conf new file mode 100644 index 0000000..a36ecfe --- /dev/null +++ b/proxy/nginx.conf @@ -0,0 +1,26 @@ +# nginx/nginx.conf +events { + worker_connections 1024; +} + +http { + server { + listen 80; + location / { + proxy_pass http://front:3000/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /back/ { + proxy_pass http://back:3001/; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + } +} \ No newline at end of file diff --git a/traque-back/index.js b/traque-back/index.js index 8eda696..358435d 100644 --- a/traque-back/index.js +++ b/traque-back/index.js @@ -1,4 +1,4 @@ -import { createServer } from "https"; +import { createServer } from "http"; import express from "express"; import { Server } from "socket.io"; @@ -14,19 +14,16 @@ const PORT = process.env.PORT; export const app = express() -const httpsServer = createServer({ - key: readFileSync(process.env.SSL_KEY, 'utf-8'), - cert: readFileSync(process.env.SSL_CERT, 'utf-8') -}, app); +const httpServer = createServer({}, app); -httpsServer.listen(PORT, HOST, () => { - console.log(`Server running`); +httpServer.listen(PORT, HOST, () => { + console.log("Server running on http://" + HOST + ":" + PORT); }); //set cors to allow all origins -export const io = new Server(httpsServer, { +export const io = new Server(httpServer, { cors: { origin: "*", methods: ["GET", "POST"] @@ -35,4 +32,4 @@ export const io = new Server(httpsServer, { initAdminSocketHandler(); initTeamSocket(); -initPhotoUpload(); \ No newline at end of file +initPhotoUpload(); diff --git a/traque-front/components/admin/teamEdit.jsx b/traque-front/components/admin/teamEdit.jsx index e8f845a..913a9df 100644 --- a/traque-front/components/admin/teamEdit.jsx +++ b/traque-front/components/admin/teamEdit.jsx @@ -12,8 +12,13 @@ export default function TeamEdit({ selectedTeamId, setSelectedTeamId }) { const teamImage = useRef(null); const [newTeamName, setNewTeamName] = React.useState(''); const { updateTeam, getTeamName, removeTeam, getTeam, teams } = useAdmin(); - const [team, setTeam] = useState({}) - const SERVER_URL = "https://" + process.env.NEXT_PUBLIC_SOCKET_HOST + ":" + process.env.NEXT_PUBLIC_SOCKET_PORT; + const [team, setTeam] = useState({}); + var protocol = "https://"; + if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") { + protocol = "http://"; + } + const SERVER_URL = protocol + process.env.NEXT_PUBLIC_SOCKET_HOST + "/back"; + console.log(SERVER_URL); useEffect(() => { let team = getTeam(selectedTeamId); diff --git a/traque-front/components/team/enemyTeamModal.jsx b/traque-front/components/team/enemyTeamModal.jsx index f8d1873..6064552 100644 --- a/traque-front/components/team/enemyTeamModal.jsx +++ b/traque-front/components/team/enemyTeamModal.jsx @@ -17,7 +17,12 @@ export function EnemyTeamModal({ visible, onClose }) { imageRef.current.src = SERVER_URL + "/photo/enemy?team=" + teamId.toString() + "&t=" + new Date().getTime(); } - const SERVER_URL = "https://" + process.env.NEXT_PUBLIC_SOCKET_HOST + ":" + process.env.NEXT_PUBLIC_SOCKET_PORT; + var protocol = "https://"; + if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") { + protocol = "http://"; + } + const SERVER_URL = protocol + process.env.NEXT_PUBLIC_SOCKET_HOST + "/back"; + console.log(SERVER_URL); return (visible && <>
diff --git a/traque-front/components/team/waitingScreen.jsx b/traque-front/components/team/waitingScreen.jsx index 306b4c0..5958bdf 100644 --- a/traque-front/components/team/waitingScreen.jsx +++ b/traque-front/components/team/waitingScreen.jsx @@ -8,7 +8,12 @@ export function WaitingScreen() { const { name, teamId } = useGame(); const { gameSettings } = useTeamContext(); const imageRef = useRef(null); - const SERVER_URL = "https://" + process.env.NEXT_PUBLIC_SOCKET_HOST + ":" + process.env.NEXT_PUBLIC_SOCKET_PORT; + var protocol = "https://"; + if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") { + protocol = "http://"; + } + const SERVER_URL = protocol + process.env.NEXT_PUBLIC_SOCKET_HOST + "/back"; + console.log(SERVER_URL); function sendImage() { let data = new FormData(); diff --git a/traque-front/context/socketContext.jsx b/traque-front/context/socketContext.jsx index 5bd13cf..3cad8c7 100644 --- a/traque-front/context/socketContext.jsx +++ b/traque-front/context/socketContext.jsx @@ -3,12 +3,21 @@ import { createContext, useContext, useMemo } from "react"; const { io } = require("socket.io-client"); -const SOCKET_URL = 'wss://' + process.env.NEXT_PUBLIC_SOCKET_HOST + ':' + process.env.NEXT_PUBLIC_SOCKET_PORT; +var proto = "wss://"; +if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") { + proto = "ws://"; +} +const SOCKET_URL = proto + process.env.NEXT_PUBLIC_SOCKET_HOST; const USER_SOCKET_URL = SOCKET_URL + "/player"; const ADMIN_SOCKET_URL = SOCKET_URL + "/admin"; -export const teamSocket = io(USER_SOCKET_URL); -export const adminSocket = io(ADMIN_SOCKET_URL); +export const teamSocket = io(USER_SOCKET_URL, { + path: "/back/socket.io", +}); +export const adminSocket = io(ADMIN_SOCKET_URL, { + path: "/back/socket.io", +}); + export const SocketContext = createContext(); export default function SocketProvider({ children }) {