Repository navigation
Description
What
The API base URL is derived ad-hoc in ~12 files, each re-declaring process.env.NEXT_PUBLIC_API_URL || '<default>' with inconsistent defaults, and the cloud host is hardcoded in two places (the root cause class of #217). This should be consolidated into a single config helper.
Current state
Pattern A — internal server base (AEO_SERVER_URL/serverUrl, used for server-to-server fetches), with two different defaults:
| Default | Files |
|---|---|
'http://localhost:80' |
app/[locale]/(onboarding)/dashboard/onboarding/page.tsx, app/[locale]/(dashboard)/dashboard/brands/new/page.tsx, app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsx, app/api/cron/daily-tracking/route.ts, lib/mcp/data.ts |
'http://localhost' |
app/api/stripe/success/route.ts, lib/actions/prompt-suggestions.ts, lib/actions/volumes.ts, lib/actions/tracking.ts (×3), lib/actions/content.ts |
(http://localhost and http://localhost:80 happen to resolve to the same place, so there's no live bug — but the divergence is a footgun and pure duplication.)
Pattern B — public/cloud snippet host (the user-facing t.js install snippet), with a hardcoded cloud URL in two files:
const apiUrl = isCloud ? 'https://api.ansvisor.com' : process.env.NEXT_PUBLIC_API_URL;app/[locale]/(dashboard)/dashboard/traffic/page.tsxapp/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx
This is exactly the surface that caused #217 (a stale hardcoded host shipped to every cloud customer).
Proposed
Add a single config module (e.g. web/src/config/api.ts) exposing two helpers — they serve different purposes and shouldn't be collapsed into one:
// Internal server-to-server base (fetches to the aeo-server).
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:80';
// Public host for the user-facing tracking snippet (t.js).
export function getPublicApiBaseUrl(): string {
const isCloud = process.env.NEXT_PUBLIC_IS_CLOUD === 'true';
return isCloud ? 'https://api.ansvisor.com' : (process.env.NEXT_PUBLIC_API_URL ?? '');
}Then replace all call sites above with imports from this module.
Acceptance
- One config module owns the API base URL(s); no other file declares its own
NEXT_PUBLIC_API_URL || ...fallback - The localhost default is unified (single value)
- The cloud host
https://api.ansvisor.comappears exactly once in the codebase -
yarn typecheck/lint/buildpass; no behavior change
Notes
- Refactor only, no behavior change. Directly hardens against the fix(traffic): tracking snippet points to dead api.ansops.ai host in cloud mode #217 class of bug by making the cloud host single-source.
Activity
BharadwajKanneveti commentedon Jun 21, 2026
Hi @gkhngyk can I work on this issue?
gkhngyk commentedon Jun 22, 2026
Assigned — thanks @BharadwajKanneveti! 🎉 A couple of pointers: keep the two patterns separate — the internal server base (
AEO_SERVER_URL, server-to-server) and the public cloud snippet host (t.jsinstall snippet) — ideally as two small helpers in a single config module so the cloud host (#217's root cause) lives in exactly one place. Pick one default for the internal base and use it everywhere.yarn build/lint/typecheckfromweb/should stay green.