Skip to content

Commit 9d9ea37

Browse files
feat: make backend worker API URL configurable via WORKER_API_URL
The backend worker API host/port was hardcoded to localhost:3060 in both the worker (api.ts) and the web app that calls it (workerApi/actions.ts). Add a WORKER_API_URL env var (default http://localhost:3060): the web app dials it, and the worker derives its listen port from it, so the two can't drift. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3a7bf2d commit 9d9ea37

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/backend/src/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { SINGLE_TENANT_ORG_ID } from './constants.js';
1414
import z from 'zod';
1515

1616
const logger = createLogger('api');
17-
const PORT = 3060;
17+
18+
const workerApiUrl = new URL(env.WORKER_API_URL);
19+
const PORT = Number(workerApiUrl.port) || (workerApiUrl.protocol === "https:" ? 443 : 80);
1820

1921
export class Api {
2022
private server: http.Server;

packages/shared/src/env.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ const options = {
172172
// Zoekt
173173
ZOEKT_WEBSERVER_URL: z.string().url().default("http://localhost:6070"),
174174

175+
WORKER_API_URL: z.string().url().default("http://localhost:3060"),
176+
175177
// Auth
176178
AUTH_SECRET: z.string(),
177179
AUTH_URL: z.string().url(),

packages/web/src/features/workerApi/actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { unexpectedError } from "@/lib/serviceError";
55
import { withAuth, withOptionalAuth } from "@/middleware/withAuth";
66
import { withMinimumOrgRole } from "@/middleware/withMinimumOrgRole";
77
import { OrgRole } from "@sourcebot/db";
8+
import { env } from "@sourcebot/shared";
89
import z from "zod";
910

10-
const WORKER_API_URL = 'http://localhost:3060';
11+
const WORKER_API_URL = env.WORKER_API_URL;
1112

1213
export const syncConnection = async (connectionId: number) => sew(() =>
1314
withAuth(({ role }) =>

0 commit comments

Comments
 (0)