Repository navigation
chore(repo): move local dev ports into a dedicated range - #96
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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:@nx/expo:startdeclares"port": { "default": 19000 }— a leftover of the old Expo convention — sonx dev mobilealready ran Metro on 19000, the port the web app now takes. Meanwhiledev-iosanddev-androidgo throughexpo 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 thestarttarget itself, so every route into it inherits it, plus explicitly on the two run commands and on the rawpackage.jsonscripts that bypass Nx.next devtakes-p 19000. It read noPORTand would have stayed on 3000.localhost:3000defaults (WEB_APP_URLinlibs/env,DEVELOPMENT_URLinapps/web) and their tests, the MCP inspector URLs inapps/api/project.json, and two stale9900references inlibs/assets/README.md..env.templatefiles, so the nextcp .env.template .envdoes not reintroduce the collisions.--portis documented forexpo startand forrun:ios/run:android.RCT_METRO_PORTworks 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:
19010:5432still reaches Postgres on 5432PORTdefaults inlibs/envnext startcontainerPort: 3000The
PORTdefaults are the one real landmine. notify and worker declare noPORTin 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 setsPORT: "9000"explicitly.The two defaults that did move are dev-only, verified against the infra manifests:
WEB_APP_URLis set explicitly in every deployment (value: "https://recomend.app", or from a secret), so the Zod default is never reached.DEVELOPMENT_URLis read only on theNODE_ENV !== 'production'branch (utils.ts:68).CI is unaffected. Every workflow writes its own
.envwith a heredoc rather than reading a template, and the integration tests get their database from testcontainers on a random host port, so they never seeDB_PORT.One consequence for anyone else cloning: an existing local
.envkeeps its old ports and has to be updated, since.envis gitignored and only the templates ship.Test Plan
docker compose configresolves the host ports to 19010-19014 against the real container portsnx show project mobileresolvesstart.options.portto 19004 and both run commands carry--port 19004apps/mobilebun nx dev webserves on 19000 andbun nx dev mobilebundles on 19004, with both running at oncebun nx dev-ios mobileattaches to 19004 rather than starting a second bundler on 8081