Skip to content

refactor(web): consolidate API base URL into a single config helper #228

Closed

Description

@gkhngyk

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.tsx
  • app/[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.com appears exactly once in the codebase
  • yarn typecheck / lint / build pass; no behavior change

Notes

Activity

  1. added
    enhancement
    good first issue
    on Jun 10, 2026
  2. BharadwajKanneveti commented on Jun 21, 2026

    @BharadwajKanneveti
    Contributor

    Hi @gkhngyk can I work on this issue?

  3. gkhngyk commented on Jun 22, 2026

    @gkhngyk
    ContributorAuthor

    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.js install 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/typecheck from web/ should stay green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions