Skip to content

Commit 93998d7

Browse files
OrcIncclaude
andcommitted
fix(frontend): derive API base URL from daemon port, drop hardcoded 3001
The daemon binds AO_PORT (default 3001) and writes the actual port to running.json. Baking http://127.0.0.1:3001 into the client meant any user overriding AO_PORT would silently hit the wrong address. Replace the pre-built constant-port client with a createApiClient(baseUrl) factory plus a baseURLForPort helper, so the wiring layer passes the port discovered from running.json (via IPC). DEFAULT_PORT remains only as a documented fallback. Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent c5d667f commit 93998d7

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

‎frontend/src/api/client.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import createClient from "openapi-fetch";
22
import type { paths } from "./schema";
33

4-
// Typed client for the daemon's loopback /api/v1 surface. Request and response
5-
// types come from ./schema.ts, which is generated from the backend OpenAPI
6-
// document (`npm run api` at the repo root) — never hand-maintained.
7-
export const api = createClient<paths>({ baseUrl: "http://127.0.0.1:3001" });
4+
// The daemon binds DEFAULT_PORT unless AO_PORT overrides it (see config.go),
5+
// and writes the port it actually bound to running.json (runfile.File.Port).
6+
// DEFAULT_PORT only mirrors config.DefaultPort as a last-resort fallback for
7+
// when the runfile hasn't been read yet — clients must NOT assume it.
8+
export const DEFAULT_PORT = 3001;
9+
10+
// baseURLForPort builds the loopback base URL for a known daemon port. Pass the
11+
// port read from running.json; default only as a fallback.
12+
export const baseURLForPort = (port: number = DEFAULT_PORT): string =>
13+
`http://127.0.0.1:${port}`;
14+
15+
// createApiClient builds a typed openapi-fetch client for the daemon's
16+
// /api/v1 surface. The renderer cannot read running.json directly, so the
17+
// wiring layer must read it (via IPC to the main process) and pass the resolved
18+
// base URL here — hardcoding DEFAULT_PORT would silently break any user who
19+
// overrides AO_PORT. Request/response types come from ./schema.ts, generated
20+
// from the backend OpenAPI document (`npm run api` at the repo root).
21+
export const createApiClient = (baseUrl: string) =>
22+
createClient<paths>({ baseUrl });
823

924
// Re-export the generated component schemas for convenient use in the renderer,
1025
// e.g. components["schemas"]["Project"], "Session", "APIError".

0 commit comments

Comments
 (0)