From 29b97443129b4b6224466b0ef28193eaf534ff84 Mon Sep 17 00:00:00 2001 From: loup Date: Mon, 23 Nov 2026 11:39:41 +0100 Subject: [PATCH] chore(repo): move local dev ports into a dedicated range 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. --- .env.template | 6 +++--- README.md | 22 ++++++++++++++++++++++ apps/api/.env.template | 2 +- apps/api/project.json | 4 ++-- apps/mobile/package.json | 4 ++-- apps/mobile/project.json | 7 +++++-- apps/notify/.env.template | 2 +- apps/web/project.json | 2 +- apps/web/src/lib/utils.spec.ts | 2 +- apps/web/src/lib/utils.ts | 2 +- apps/worker/.env.template | 2 +- libs/assets/README.md | 4 ++-- libs/env/src/lib/env.validation.spec.ts | 2 +- libs/env/src/lib/env.validation.ts | 2 +- 14 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.env.template b/.env.template index 7a9559d7..86f24f47 100644 --- a/.env.template +++ b/.env.template @@ -3,19 +3,19 @@ DB_USER= DB_PASSWORD= DB_NAME= DB_HOST= -DB_PORT= +DB_PORT=19010 DATABASE_URL= WEB_APP_URL= # REDIS REDIS_HOST= -REDIS_PORT= +REDIS_PORT=19011 REDIS_PASSWORD= # TYPESENSE TYPESENSE_HOST= -TYPESENSE_PORT= +TYPESENSE_PORT=19012 TYPESENSE_PROTOCOL= TYPESENSE_API_KEY= diff --git a/README.md b/README.md index 6d34f447..1a9be19f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,28 @@ cp .env.template .env.local bun run start ``` +### Local ports + +Everything in development lives in **19000-19019**, so the repo can run alongside other +projects without colliding on 3000, 6379 or 8108. The host ports come from `.env`; the +container ports behind them are untouched, as are the defaults the deployed images use. + +| Port | Service | Set in | +| ----- | -------------- | --------------------------------------- | +| 19000 | web | `apps/web/project.json` (`next dev -p`) | +| 19001 | api | `apps/api/.env` | +| 19002 | notify | `apps/notify/.env` | +| 19003 | worker | `apps/worker/.env` | +| 19004 | mobile (Metro) | `apps/mobile/project.json` | +| 19010 | postgres | `.env` (`DB_PORT`) | +| 19011 | redis | `.env` (`REDIS_PORT`) | +| 19012 | typesense | `.env` (`TYPESENSE_PORT`) | +| 19013 | s3 (rustfs) | `.env` (`S3_PORT`) | +| 19014 | s3 console | `.env` (`S3_CONSOLE_PORT`) | + +Mobile needs its port pinned explicitly: `@nx/expo:start` defaults Metro to 19000, which +is the web app's port here, while `expo run:ios` and `expo run:android` default to 8081. + ## 🤝 Contributing Contributions are welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md) for how to submit issues and pull requests. diff --git a/apps/api/.env.template b/apps/api/.env.template index f13ce56d..6f824f7d 100644 --- a/apps/api/.env.template +++ b/apps/api/.env.template @@ -1,4 +1,4 @@ -PORT=9000 +PORT=19001 HOST=0.0.0.0 API_URL= diff --git a/apps/api/project.json b/apps/api/project.json index f4b9b7bb..195670a4 100644 --- a/apps/api/project.json +++ b/apps/api/project.json @@ -86,11 +86,11 @@ "continuous": true, "executor": "nx:run-commands", "options": { - "command": "HOST=localhost bunx @modelcontextprotocol/inspector --web --transport http --server-url http://localhost:9000/mcp" + "command": "HOST=localhost bunx @modelcontextprotocol/inspector --web --transport http --server-url http://localhost:19001/mcp" }, "configurations": { "cli": { - "command": "HOST=localhost bunx @modelcontextprotocol/inspector --cli --transport http --server-url http://localhost:9000/mcp" + "command": "HOST=localhost bunx @modelcontextprotocol/inspector --cli --transport http --server-url http://localhost:19001/mcp" } } }, diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 67f01b88..1e1f7890 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -4,8 +4,8 @@ "main": "index.js", "private": true, "scripts": { - "android": "expo run:android", - "ios": "expo run:ios", + "android": "expo run:android --port 19004", + "ios": "expo run:ios --port 19004", "lint": "expo lint" }, "dependencies": { diff --git a/apps/mobile/project.json b/apps/mobile/project.json index 8ad966c4..cc11a522 100644 --- a/apps/mobile/project.json +++ b/apps/mobile/project.json @@ -17,6 +17,9 @@ "command": "tsc --noEmit -p apps/mobile/tsconfig.app.json" } }, + "start": { + "options": { "port": 19004 } + }, "dev": { "executor": "nx:run-commands", "options": { @@ -26,13 +29,13 @@ "dev-ios": { "executor": "nx:run-commands", "options": { - "command": "APP_VARIANT=development nx run-ios mobile" + "command": "APP_VARIANT=development nx run-ios mobile --port 19004" } }, "dev-android": { "executor": "nx:run-commands", "options": { - "command": "APP_VARIANT=development nx run-android mobile" + "command": "APP_VARIANT=development nx run-android mobile --port 19004" } }, "prebuild": { diff --git a/apps/notify/.env.template b/apps/notify/.env.template index b6b80d15..459fbcac 100644 --- a/apps/notify/.env.template +++ b/apps/notify/.env.template @@ -1,4 +1,4 @@ -PORT=9001 +PORT=19002 HOST=0.0.0.0 ASSETS_BASE_URL= diff --git a/apps/web/project.json b/apps/web/project.json index 57ee0c33..a10698c1 100644 --- a/apps/web/project.json +++ b/apps/web/project.json @@ -14,7 +14,7 @@ "serve": { "dependsOn": ["^build", "api:serve"], "options": { - "command": "bun --bun next dev" + "command": "bun --bun next dev -p 19000" } }, "start": { diff --git a/apps/web/src/lib/utils.spec.ts b/apps/web/src/lib/utils.spec.ts index dce6b9b0..33212060 100644 --- a/apps/web/src/lib/utils.spec.ts +++ b/apps/web/src/lib/utils.spec.ts @@ -61,6 +61,6 @@ describe('getURL', () => { NEXT_PUBLIC_VERCEL_URL: undefined, NODE_ENV: 'development', }), - ).toBe('http://localhost:3000'); + ).toBe('http://localhost:19000'); }); }); diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts index 4aebc5b7..a26890a2 100644 --- a/apps/web/src/lib/utils.ts +++ b/apps/web/src/lib/utils.ts @@ -44,7 +44,7 @@ export function toISO8601Duration(minutes: number): string { } const PRODUCTION_URL = 'https://recomend.app'; -const DEVELOPMENT_URL = 'http://localhost:3000'; +const DEVELOPMENT_URL = 'http://localhost:19000'; /** * The site's own origin, never with a trailing slash. diff --git a/apps/worker/.env.template b/apps/worker/.env.template index 0812e7ca..df0d0fed 100644 --- a/apps/worker/.env.template +++ b/apps/worker/.env.template @@ -1,2 +1,2 @@ -PORT=9002 +PORT=19003 HOST=0.0.0.0 \ No newline at end of file diff --git a/libs/assets/README.md b/libs/assets/README.md index 142c03ce..2433631b 100644 --- a/libs/assets/README.md +++ b/libs/assets/README.md @@ -94,8 +94,8 @@ it explicitly, e.g. `apps/notify/project.json`: } ``` -Locally, `${ASSETS_BASE_URL}` resolves to `http://localhost:9900/medias/static`, -so the example above resolves to `http://localhost:9900/medias/static/app/icon.png`. +Locally, `${ASSETS_BASE_URL}` resolves to `http://localhost:19013/medias/static`, +so the example above resolves to `http://localhost:19013/medias/static/app/icon.png`. ## Local dev diff --git a/libs/env/src/lib/env.validation.spec.ts b/libs/env/src/lib/env.validation.spec.ts index 54aa5950..653182fa 100644 --- a/libs/env/src/lib/env.validation.spec.ts +++ b/libs/env/src/lib/env.validation.spec.ts @@ -84,7 +84,7 @@ describe('commonSchema', () => { const result = commonSchema.parse({}); expect(result.NODE_ENV).toBe('development'); expect(result.LOG_LEVEL).toBe('info'); - expect(result.WEB_APP_URL).toBe('http://localhost:3000'); + expect(result.WEB_APP_URL).toBe('http://localhost:19000'); }); it('rejects an unsupported NODE_ENV', () => { diff --git a/libs/env/src/lib/env.validation.ts b/libs/env/src/lib/env.validation.ts index 1a655a8e..353d9c75 100644 --- a/libs/env/src/lib/env.validation.ts +++ b/libs/env/src/lib/env.validation.ts @@ -30,7 +30,7 @@ export const extensionSchema = redisSchema; export const commonSchema = extensionSchema.extend({ NODE_ENV: z.enum(['development', 'production', 'test']).default('development'), LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'), - WEB_APP_URL: z.url().default('http://localhost:3000'), + WEB_APP_URL: z.url().default('http://localhost:19000'), }); // Static assets served from RustFS/S3 (see libs/assets)