Skip to content

fix(server): accept SERVER_PORT alias and fail fast on PORT/SERVER_PORT mismatch - #312

Merged
davidmckayv merged 1 commit into
CopilotKit:mainfrom
Ayush7614:fix/server-port-server_port-alias
Sep 1, 2026
Merged

fix(server): accept SERVER_PORT alias and fail fast on PORT/SERVER_PORT mismatch#312
davidmckayv merged 1 commit into
CopilotKit:mainfrom
Ayush7614:fix/server-port-server_port-alias

Conversation

@Ayush7614

@Ayush7614 Ayush7614 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The server only read PORT (server/src/index.ts:146):

ts const port = Number.parseInt(process.env.PORT ?? "3001", 10);

while scripts/start.sh and app/vite.config.ts honour SERVER_PORT/APP_PORT, and docs/configuration.md + .env.example document SERVER_PORT as the setting. An operator who followed the docs and set SERVER_PORT=4000 (or edited only PORT) ended up with:

  • server on 3001
  • Vite proxy + start.sh health-check on 4000
  • 200 from whatever else was on 3001 accepted as proof, then HTML parsed as JSON several stages later

Dockerfile/compose masked it because they set PORT directly.

Fix

  • server/src/index.ts:145-155: read PORT ?? SERVER_PORT ?? "3001", preferring PORT but falling back to SERVER_PORT. If both are set and disagree, throw at boot where somebody is looking instead of failing late as a JSON parse error.
  • .env.example:10-20: comment updated to describe the alias behaviour and that a single edit now suffices (both equal remains valid).

Behaviour verified:

PORT=4000 -> 4000
SERVER_PORT=4000 -> 4000
PORT=4000 SERVER_PORT=4000 -> 4000
PORT=4000 SERVER_PORT=4001 -> throw "PORT (4000) and SERVER_PORT (4001) disagree"

Verification

bun run lint — pass (0 warnings)
bun run format:check — pass
Manual port-logic checks above — pass
No schema, migration, or dependency changes.

…RT mismatch

The server only read PORT while scripts/start.sh and app/vite.config.ts
honour SERVER_PORT/APP_PORT. An operator who followed docs and set
SERVER_PORT=4000 ended up with a server on 3001 and a proxy on 4000
that accepted whatever else was on 3001 (HTML as JSON). Now the server
prefers PORT but falls back to SERVER_PORT and refuses to start when
both are set to different values, so a single edit works and a split
edit fails where somebody is looking. .env.example comment updated to
match the new behaviour.

@davidmckayv davidmckayv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and the hard failure is the right one: the trap the .env.example comment already described at length was a silent misconfiguration, and this makes it loud. Checked the deploy paths, nothing sets PORT and SERVER_PORT to different values (the PORT: "4300" in docker-compose.yml is the supervisor, a different process). CI green.

@davidmckayv
davidmckayv merged commit 92014a8 into CopilotKit:main Sep 1, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants