From 65c74a8df2a433ae1e9bd8966f8df6a0b0401189 Mon Sep 17 00:00:00 2001 From: Justin Leveck Date: Thu, 6 Aug 2026 07:28:37 -0700 Subject: [PATCH 1/2] Make server port configurable via PORT env var server/src/index.ts hardcoded port 3001, so the only way to run the server on a different port (e.g. to avoid colliding with another local service) was to edit source. Read PORT from the environment, defaulting to 3001 to preserve current behavior. Wires PORT=3000 through docker-compose.yml, keeping the host-facing mapping fixed at 3001:3000 so `localhost:3001` still works exactly as documented - only the container's internal port changes. Dockerfile and nginx's proxy_pass are updated to match the new internal port. --- client/nginx.conf | 2 +- docker-compose.yml | 3 ++- server/Dockerfile | 3 ++- server/src/index.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/nginx.conf b/client/nginx.conf index 3bb641c..1fdae79 100644 --- a/client/nginx.conf +++ b/client/nginx.conf @@ -6,7 +6,7 @@ server { index index.html; location /api/ { - proxy_pass http://server:3001/; + proxy_pass http://server:3000/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; diff --git a/docker-compose.yml b/docker-compose.yml index b043a69..a4843fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,12 +6,13 @@ services: container_name: git-intelligence-server environment: NODE_ENV: production + PORT: 3000 DB_FILE_PATH: /data/db.json UPLOAD_DIR: /data/uploads volumes: - server-data:/data ports: - - '3001:3001' + - '3001:3000' client: build: diff --git a/server/Dockerfile b/server/Dockerfile index 585d199..2359a6d 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -26,6 +26,7 @@ ENV NODE_ENV=production ENV DB_FILE_PATH=/data/db.json ENV UPLOAD_DIR=/data/uploads -EXPOSE 3001 +ENV PORT=3000 +EXPOSE 3000 CMD ["node", "dist/index.js"] diff --git a/server/src/index.ts b/server/src/index.ts index a16bc01..e420c04 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -9,7 +9,7 @@ import settingsRouter from './routes/settings.js'; import { errorHandler } from './middleware/errorHandler.js'; const app = express(); -const port = 3001; +const port = Number(process.env.PORT) || 3001; // Middleware app.use(cors()); From 1053c7ebe80c2fc8491d2a6446f215c7d6e2b80d Mon Sep 17 00:00:00 2001 From: Justin Leveck Date: Thu, 6 Aug 2026 07:34:08 -0700 Subject: [PATCH 2/2] Let docker-compose host ports be overridden without editing the file Anyone whose 3001 or 5173 is already taken had to edit the tracked docker-compose.yml to run the stack at all. Compose's ports list is concatenated (not replaced) across -f files, so a docker-compose.override.yml wouldn't actually fix a port collision - the base file's binding would still be attempted and still fail. Variable substitution does replace cleanly: ports now read ${SERVER_PORT:-3001} / ${CLIENT_PORT:-5173}, which docker compose resolves from a .env file (already gitignored, see .env.example) or inline env vars, with no change to defaults. Also gitignore docker-compose.override.yml, since it's the other Compose-native path someone might reach for locally and shouldn't be committed either. --- .env.example | 8 ++++++++ .gitignore | 3 +++ README.md | 17 ++++++++++++++++- docker-compose.yml | 4 ++-- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6223cce --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +# Copy to .env to override without touching docker-compose.yml. +# Both are optional - unset values fall back to the defaults below. + +# Host port for the frontend (container always listens on 80 internally) +CLIENT_PORT=5173 + +# Host port for the backend API (container always listens on 3000 internally) +SERVER_PORT=3001 diff --git a/.gitignore b/.gitignore index 93d6dbc..d8a7b80 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,9 @@ web_modules/ .env.* !.env.example +# local Docker Compose overrides +docker-compose.override.yml + # parcel-bundler cache (https://parceljs.org/) .cache .parcel-cache diff --git a/README.md b/README.md index 1a910d6..0e67b95 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,18 @@ To stop: docker compose down ``` +#### Overriding the Ports + +If `5173` or `3001` are already in use on your machine, override them without editing `docker-compose.yml`: + +```bash +cp .env.example .env +# then edit .env, or just export the values inline: +SERVER_PORT=4001 CLIENT_PORT=8080 docker compose up --build +``` + +`docker compose` automatically reads a `.env` file in the project root, so a committed `.env` is never required. Only the host-side port changes - the containers still talk to each other over the internal Docker network regardless of what you choose here. + ### Docker Compose with SSH Key for Git Pull If your repositories use SSH remotes (for example `git@github.com:...`), mount a private key into the server container: @@ -339,11 +351,14 @@ cd server && npm run test:coverage ### Ports -- Backend: `3001` (configured in `server/src/index.ts`) +- Backend: `3001` (override with the `PORT` env var when running the server directly, e.g. `PORT=4001 npm run dev` in `server/`) - Frontend: `5173` (Vite default) +Running via Docker Compose instead? See [Overriding the Ports](#overriding-the-ports) - use `SERVER_PORT`/`CLIENT_PORT` rather than `PORT`, since those control the host-side mapping while the containers keep talking to each other over the internal Docker network. + ### Environment Variables +- Server port: `PORT` (default: `3001`) - Frontend API base URL: `VITE_API_BASE_URL` (default: `http://localhost:3001`) - Server DB path: `DB_FILE_PATH` (default: `/db.json`) - Server upload directory: `UPLOAD_DIR` (default: `/uploads/`) diff --git a/docker-compose.yml b/docker-compose.yml index a4843fe..a800116 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: volumes: - server-data:/data ports: - - '3001:3000' + - '${SERVER_PORT:-3001}:3000' client: build: @@ -24,7 +24,7 @@ services: depends_on: - server ports: - - '5173:80' + - '${CLIENT_PORT:-5173}:80' volumes: server-data: