From b28d4f72f874701e67cccc559d682b253be43ec0 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 19:13:45 +0200 Subject: [PATCH] Make worker Express server port configurable via environment variable (#1748) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make worker Express server port configurable via environment variable - Add PORT environment variable support with fallback to 3005 - Update console log to display actual port being used - Add documentation note in SELF_HOST.md - Add tests for port configuration behavior Fixes ENG-2586 Co-Authored-By: mogery@sideguide.dev * Delete apps/api/src/__tests__/snips/worker-port-config.test.ts * fix(ci): explicit separate port bindings --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: mogery@sideguide.dev Co-authored-by: Gergő Móricz --- .github/workflows/test-server-self-host.yml | 8 ++++++-- .github/workflows/test-server.yml | 8 ++++++-- SELF_HOST.md | 2 ++ apps/api/src/services/queue-worker.ts | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-server-self-host.yml b/.github/workflows/test-server-self-host.yml index 6209f2369..aff1167a7 100644 --- a/.github/workflows/test-server-self-host.yml +++ b/.github/workflows/test-server-self-host.yml @@ -6,9 +6,7 @@ on: - main env: - PORT: 3002 REDIS_URL: redis://localhost:6379 - HOST: 0.0.0.0 ENV: ${{ secrets.ENV }} TEST_SUITE_SELF_HOSTED: true USE_GO_MARKDOWN_PARSER: true @@ -100,9 +98,15 @@ jobs: working-directory: ./ - name: Start server run: npm run start:production > api.log 2>&1 & + env: + PORT: 3002 + HOST: 0.0.0.0 working-directory: ./apps/api - name: Start worker run: npm run workers > worker.log 2>&1 & + env: + PORT: 3005 + HOST: 0.0.0.0 working-directory: ./apps/api - name: Start playwright if: matrix.engine == 'playwright' diff --git a/.github/workflows/test-server.yml b/.github/workflows/test-server.yml index df25b00e1..c30056257 100644 --- a/.github/workflows/test-server.yml +++ b/.github/workflows/test-server.yml @@ -7,11 +7,9 @@ on: env: BULL_AUTH_KEY: ${{ secrets.BULL_AUTH_KEY }} - HOST: ${{ secrets.HOST }} POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }} POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - PORT: ${{ secrets.PORT }} REDIS_URL: ${{ secrets.REDIS_URL }} SUPABASE_ANON_TOKEN: ${{ secrets.SUPABASE_ANON_TOKEN }} SUPABASE_SERVICE_TOKEN: ${{ secrets.SUPABASE_SERVICE_TOKEN }} @@ -101,10 +99,16 @@ jobs: working-directory: ./apps/api/sharedLibs/pdf-parser - name: Start the application run: npm run start:production > api.log 2>&1 & + env: + PORT: 3002 + HOST: 0.0.0.0 working-directory: ./apps/api id: start_app - name: Start worker run: npm run workers > worker.log 2>&1 & + env: + PORT: 3005 + HOST: 0.0.0.0 working-directory: ./apps/api id: start_workers - name: Start index worker diff --git a/SELF_HOST.md b/SELF_HOST.md index a716688f6..dd61faf7f 100644 --- a/SELF_HOST.md +++ b/SELF_HOST.md @@ -42,6 +42,8 @@ Create an `.env` in the root directory using the template below. PORT=3002 HOST=0.0.0.0 +# Note: PORT is used by both the main API server and worker liveness check endpoint + # To turn on DB authentication, you need to set up Supabase. USE_DB_AUTHENTICATION=false diff --git a/apps/api/src/services/queue-worker.ts b/apps/api/src/services/queue-worker.ts index 57eb1c0a9..f59640c72 100644 --- a/apps/api/src/services/queue-worker.ts +++ b/apps/api/src/services/queue-worker.ts @@ -1620,8 +1620,9 @@ app.get("/liveness", (req, res) => { } }); -app.listen(3005, () => { - _logger.info("Liveness endpoint is running on port 3005"); +const workerPort = process.env.PORT || 3005; +app.listen(workerPort, () => { + _logger.info(`Liveness endpoint is running on port ${workerPort}`); }); (async () => {