From 90555891f8308bd04ebcd8fa3139fc4b21b991ba Mon Sep 17 00:00:00 2001 From: Ralex <95540504+Ralex91@users.noreply.github.com> Date: Sun, 19 Oct 2025 12:32:46 +0200 Subject: [PATCH] fix(docker): fix config files reading & add compose file --- .env.example | 2 +- Dockerfile | 1 + compose.yml | 13 ++++++++ packages/config/game.json | 4 --- packages/config/quizz/example.json | 41 -------------------------- packages/socket/src/env.ts | 2 ++ packages/socket/src/index.ts | 8 +++-- packages/socket/src/services/config.ts | 6 +++- packages/web/package.json | 2 +- 9 files changed, 29 insertions(+), 50 deletions(-) create mode 100644 compose.yml delete mode 100644 packages/config/game.json delete mode 100644 packages/config/quizz/example.json diff --git a/.env.example b/.env.example index dc87529..37b9549 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,2 @@ +WEB_ORIGIN=http://localhost:3000 # Default: http://localhost:3000, for allow all origins use '*' SOCKET_URL=http://localhost:3001 # Default: http://localhost:3001 -SOCKER_PORT=3001 # Default: 3001 diff --git a/Dockerfile b/Dockerfile index cb58f84..92e640c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,6 +67,7 @@ EXPOSE 3000 5505 # Environment variables ENV NODE_ENV=production +ENV CONFIG_PATH=/app/config # Start both services (Next.js web app + Socket server) CMD ["sh", "-c", "node packages/web/server.js & node packages/socket/dist/index.cjs"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..46701b8 --- /dev/null +++ b/compose.yml @@ -0,0 +1,13 @@ +version: "3.8" + +services: + rahoot: + image: rahoot + ports: + - "3000:3000" + - "3001:3001" + volumes: + - ./config:/app/config # Path to your game config + environment: + - WEB_ORIGIN=http://localhost:3000 + - SOCKET_URL=http://localhost:3001 diff --git a/packages/config/game.json b/packages/config/game.json deleted file mode 100644 index 66f12d9..0000000 --- a/packages/config/game.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "managerPassword": "PASSWORD", - "music": true -} \ No newline at end of file diff --git a/packages/config/quizz/example.json b/packages/config/quizz/example.json deleted file mode 100644 index c048d43..0000000 --- a/packages/config/quizz/example.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "subject": "Example Quizz", - "questions": [ - { - "question": "What is good answer ?", - "answers": [ - "No", - "Good answer", - "No", - "No" - ], - "solution": 1, - "cooldown": 5, - "time": 15 - }, - { - "question": "What is good answer with image ?", - "answers": [ - "No", - "No", - "No", - "Good answer" - ], - "image": "https://placehold.co/600x400.png", - "solution": 3, - "cooldown": 5, - "time": 20 - }, - { - "question": "What is good answer with two answers ?", - "answers": [ - "Good answer", - "No" - ], - "image": "https://placehold.co/600x400.png", - "solution": 0, - "cooldown": 5, - "time": 20 - } - ] -} \ No newline at end of file diff --git a/packages/socket/src/env.ts b/packages/socket/src/env.ts index b64a0ab..3be0d1d 100644 --- a/packages/socket/src/env.ts +++ b/packages/socket/src/env.ts @@ -3,10 +3,12 @@ import { z } from "zod/v4" const env = createEnv({ server: { + WEB_ORIGIN: z.string().optional().default("http://localhost:3000"), SOCKER_PORT: z.string().optional().default("3001"), }, runtimeEnv: { + WEB_ORIGIN: process.env.WEB_ORIGIN, SOCKER_PORT: process.env.SOCKER_PORT, }, }) diff --git a/packages/socket/src/index.ts b/packages/socket/src/index.ts index 646831e..ae25428 100644 --- a/packages/socket/src/index.ts +++ b/packages/socket/src/index.ts @@ -7,11 +7,15 @@ import Registry from "@rahoot/socket/services/registry" import { withGame } from "@rahoot/socket/utils/game" import { Server as ServerIO } from "socket.io" -const io: Server = new ServerIO() +const io: Server = new ServerIO({ + cors: { + origin: [env.WEB_ORIGIN], + }, +}) Config.init() const registry = Registry.getInstance() -const port = env.SOCKER_PORT || 3001 +const port = 3001 console.log(`Socket server running on port ${port}`) io.listen(Number(port)) diff --git a/packages/socket/src/services/config.ts b/packages/socket/src/services/config.ts index e052542..92db828 100644 --- a/packages/socket/src/services/config.ts +++ b/packages/socket/src/services/config.ts @@ -2,8 +2,12 @@ import { QuizzWithId } from "@rahoot/common/types/game" import fs from "fs" import { resolve } from "path" +const inContainerPath = process.env.CONFIG_PATH + const getPath = (path: string = "") => - resolve(process.cwd(), "../../config", path) + inContainerPath + ? resolve(inContainerPath, path) + : resolve(process.cwd(), "../../config", path) class Config { static init() { diff --git a/packages/web/package.json b/packages/web/package.json index 7d547d7..5f9c43b 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -4,7 +4,7 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "node .next/standalone/packages/web/server.js", + "start": "next start", "lint": "eslint" }, "dependencies": {