Use APP_PORT consistently
This commit is contained in:
@@ -8,6 +8,6 @@ pnpm-debug.log*
|
|||||||
*.log
|
*.log
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
|
!.env.example
|
||||||
Dockerfile
|
Dockerfile
|
||||||
compose.yaml
|
compose.yaml
|
||||||
|
|
||||||
|
|||||||
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
APP_PORT=8787
|
||||||
|
|
||||||
@@ -3,15 +3,14 @@ FROM node:24-alpine
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PORT=3000
|
ENV APP_PORT=8787
|
||||||
|
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
COPY index.html styles.css game.js server.js ./
|
COPY index.html styles.css game.js server.js ./
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 8787
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
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"]
|
CMD ["node", "server.js"]
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ A notepad-playable browser game that combines Tic Tac Toe's line-making goal wit
|
|||||||
|
|
||||||
## Run With Docker Compose
|
## Run With Docker Compose
|
||||||
|
|
||||||
|
Optional: copy `.env.example` to `.env` and change `APP_PORT`.
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
docker compose up --build
|
docker compose up --build
|
||||||
```
|
```
|
||||||
@@ -37,12 +39,12 @@ docker compose down
|
|||||||
npm start
|
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:
|
Set a different port with:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$env:PORT=4000; npm start
|
$env:APP_PORT=9090; npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ services:
|
|||||||
container_name: tictactics
|
container_name: tictactics
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
PORT: 3000
|
APP_PORT: ${APP_PORT:-8787}
|
||||||
ports:
|
ports:
|
||||||
- "${APP_PORT:-8787}:3000"
|
- "${APP_PORT:-8787}:${APP_PORT:-8787}"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const fs = require("fs");
|
|||||||
const http = require("http");
|
const http = require("http");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const port = Number(process.env.PORT || 3000);
|
const appPort = Number(process.env.APP_PORT || 8787);
|
||||||
const root = __dirname;
|
const root = __dirname;
|
||||||
const clients = new Map();
|
const clients = new Map();
|
||||||
const rooms = new Map();
|
const rooms = new Map();
|
||||||
@@ -286,6 +286,6 @@ function encodeFrame(message) {
|
|||||||
return Buffer.concat([header, payload]);
|
return Buffer.concat([header, payload]);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.listen(port, () => {
|
server.listen(appPort, () => {
|
||||||
console.log(`Tictactics multiplayer server running at http://localhost:${port}`);
|
console.log(`Tictactics multiplayer server running at http://localhost:${appPort}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user