From 62d82f5344eb574f218657544f3f7375de52a2cd Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 7 May 2026 16:25:29 -0400 Subject: [PATCH] Use APP_PORT consistently --- .dockerignore | 2 +- .env.example | 2 ++ Dockerfile | 7 +++---- README.md | 6 ++++-- compose.yaml | 4 ++-- server.js | 6 +++--- 6 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .env.example diff --git a/.dockerignore b/.dockerignore index c97dc53..523ecb9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,6 +8,6 @@ pnpm-debug.log* *.log .env .env.* +!.env.example Dockerfile compose.yaml - diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..029fa5e --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +APP_PORT=8787 + diff --git a/Dockerfile b/Dockerfile index 12cab8f..dfaaaa0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,14 @@ FROM node:24-alpine WORKDIR /app ENV NODE_ENV=production -ENV PORT=3000 +ENV APP_PORT=8787 COPY package.json ./ COPY index.html styles.css game.js server.js ./ -EXPOSE 3000 +EXPOSE 8787 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD node -e "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/healthz').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" + CMD node -e "fetch('http://127.0.0.1:' + (process.env.APP_PORT || 8787) + '/healthz').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" CMD ["node", "server.js"] - diff --git a/README.md b/README.md index 33c10b4..9a31796 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ A notepad-playable browser game that combines Tic Tac Toe's line-making goal wit ## Run With Docker Compose +Optional: copy `.env.example` to `.env` and change `APP_PORT`. + ```powershell docker compose up --build ``` @@ -37,12 +39,12 @@ docker compose down npm start ``` -Then open `http://localhost:3000` in two browser windows. +Then open `http://localhost:8787` in two browser windows. Set a different port with: ```powershell -$env:PORT=4000; npm start +$env:APP_PORT=9090; npm start ``` ## Notes diff --git a/compose.yaml b/compose.yaml index b52dde3..bacf657 100644 --- a/compose.yaml +++ b/compose.yaml @@ -6,6 +6,6 @@ services: container_name: tictactics restart: unless-stopped environment: - PORT: 3000 + APP_PORT: ${APP_PORT:-8787} ports: - - "${APP_PORT:-8787}:3000" + - "${APP_PORT:-8787}:${APP_PORT:-8787}" diff --git a/server.js b/server.js index 71129d7..3657a09 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,7 @@ const fs = require("fs"); const http = require("http"); const path = require("path"); -const port = Number(process.env.PORT || 3000); +const appPort = Number(process.env.APP_PORT || 8787); const root = __dirname; const clients = new Map(); const rooms = new Map(); @@ -286,6 +286,6 @@ function encodeFrame(message) { return Buffer.concat([header, payload]); } -server.listen(port, () => { - console.log(`Tictactics multiplayer server running at http://localhost:${port}`); +server.listen(appPort, () => { + console.log(`Tictactics multiplayer server running at http://localhost:${appPort}`); });