Skip to content

chore(repo): move local dev ports into a dedicated range - #96

Merged
lxup merged 1 commit into
mainfrom
chore/local-dev-port-range
Nov 23, 2026
Merged

lxup merged 1 commit into
mainfrom
chore/local-dev-port-range

Conversation

@lxup

@lxup lxup commented Nov 23, 2026

Copy link
Copy Markdown
Member

Description

Running this repo next to another local project collided three times: the web app on 3000, Redis on 6379 and Typesense on 8108. Development now lives in a dedicated 19000-19019, so the two can run side by side.

19000  web        19010  postgres
19001  api        19011  redis
19002  notify     19012  typesense
19003  worker     19013  s3 (rustfs)
19004  mobile     19014  s3 console

The range sits clear of the usual defaults, and below the ephemeral range the OS allocates from.

Changes

Host ports already came from .env, so most of this is values. The parts worth reading:

  • Mobile needed pinning in three places, and it was the real surprise. @nx/expo:start declares "port": { "default": 19000 } — a leftover of the old Expo convention — so nx dev mobile already ran Metro on 19000, the port the web app now takes. Meanwhile dev-ios and dev-android go through expo run:*, which default to 8081. The two mobile paths already disagreed with each other, and the 8081 one was the one colliding with the other project. The port is now set on the start target itself, so every route into it inherits it, plus explicitly on the two run commands and on the raw package.json scripts that bypass Nx.
  • next dev takes -p 19000. It read no PORT and would have stayed on 3000.
  • The two hardcoded localhost:3000 defaults (WEB_APP_URL in libs/env, DEVELOPMENT_URL in apps/web) and their tests, the MCP inspector URLs in apps/api/project.json, and two stale 9900 references in libs/assets/README.md.
  • The four .env.template files, so the next cp .env.template .env does not reintroduce the collisions.
  • The range is documented in the README. A convention nobody can find will not hold.

--port is documented for expo start and for run:ios / run:android. RCT_METRO_PORT works in @expo/cli (resolveOptions.js) but is undocumented, so it is not relied on here.

Impact

Nothing outside local development moves. Checked rather than assumed:

stays why
container ports 5432, 6379, 8108, 9000, 9001 only the host side of a compose mapping moved; 19010:5432 still reaches Postgres on 5432
PORT defaults in libs/env 9000, 9001, 9002 see below
next start 3000 it is what the deployed image runs, and it matches containerPort: 3000

The PORT defaults are the one real landmine. notify and worker declare no PORT in their deployments, so those Zod defaults are what their containers actually listen on, against Services targeting 9001 and 9002. Harmonising them onto the new range would have taken both down in production. The api survives either way, since its deployment sets PORT: "9000" explicitly.

The two defaults that did move are dev-only, verified against the infra manifests:

  • WEB_APP_URL is set explicitly in every deployment (value: "https://recomend.app", or from a secret), so the Zod default is never reached.
  • DEVELOPMENT_URL is read only on the NODE_ENV !== 'production' branch (utils.ts:68).

CI is unaffected. Every workflow writes its own .env with a heredoc rather than reading a template, and the integration tests get their database from testcontainers on a random host port, so they never see DB_PORT.

One consequence for anyone else cloning: an existing local .env keeps its old ports and has to be updated, since .env is gitignored and only the templates ship.

Test Plan

  • docker compose config resolves the host ports to 19010-19014 against the real container ports
  • nx show project mobile resolves start.options.port to 19004 and both run commands carry --port 19004
  • No 8081 or 19000 left anywhere in apps/mobile
  • The 38 tests of the two changed spec files pass
  • bun nx dev web serves on 19000 and bun nx dev mobile bundles on 19004, with both running at once
  • bun nx dev-ios mobile attaches to 19004 rather than starting a second bundler on 8081
  • The other project's web and mobile still start while this one is up

Running this repo next to another local project collided three times: the web app
on 3000, Redis on 6379 and Typesense on 8108. Development now lives in
19000-19019, so the two can run side by side.

    19000 web        19010 postgres
    19001 api        19011 redis
    19002 notify     19012 typesense
    19003 worker     19013 s3
    19004 mobile     19014 s3 console

Mobile had to be pinned in three places, and it was the one real surprise.
@nx/expo:start declares `"port": { "default": 19000 }`, a leftover of the old
Expo convention, so `nx dev mobile` already ran Metro on 19000 -- the port the
web app now takes. Meanwhile `dev-ios` and `dev-android` go through
`expo run:*`, which default to 8081. The two mobile paths therefore disagreed
already, and the 8081 one was the one colliding with another project. The port
is set on the `start` target itself so every route into it inherits it, and
passed explicitly to the two run commands and to the raw package.json scripts
that bypass Nx. `--port` is documented for `expo start` and `run:ios` /
`run:android`; RCT_METRO_PORT works in @expo/cli but is not documented, so it is
not relied on here.

What deliberately keeps its old port:

- Container ports. Only the host side of a compose mapping moved, so `19010:5432`
  still reaches Postgres on 5432 and the cluster is untouched.
- The PORT defaults in libs/env, 9000, 9001 and 9002. notify and worker declare
  no PORT in their deployments, so those defaults are what their containers
  actually listen on, against a Service targeting 9001 and 9002. Harmonising
  them onto the new range would have broken both in production.
- `next start`, which the deployed image runs, stays on 3000 to match its
  containerPort. Only `next dev` takes -p.

The two hardcoded defaults that did move are dev-only: WEB_APP_URL is set
explicitly in every deployment, and DEVELOPMENT_URL is read only when NODE_ENV
is not production.

CI is unaffected: every workflow writes its own .env with a heredoc rather than
reading a template, and the integration tests get their database from
testcontainers on a random host port.

The range is in the README, since a convention nobody can find will not hold.
@lxup
lxup merged commit 0d29f8a into main Nov 23, 2026
3 checks passed
@lxup
lxup deleted the chore/local-dev-port-range branch November 23, 2026 10:51
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.

1 participant