# Externalize OpenWeatherMap base URL

**Task**: AZ-449_refactor_owm_base_url
**Name**: Externalize OWM base URL to VITE_OWM_BASE_URL
**Description**: Move the hardcoded `https://api.openweathermap.org/data/2.5/weather` URL into a Vite env var so the e2e profile's `owm-stub` can intercept OWM calls without code edits.
**Complexity**: 2 points
**Dependencies**: AZ-448_refactor_owm_api_key (same file)
**Component**: `src/features/flights/flightPlanUtils.ts`, `.env.example`, `src/vite-env.d.ts`
**Tracker**: AZ-449
**Epic**: AZ-447

## Problem

The OWM endpoint is hardcoded at `flightPlanUtils.ts:60`. The e2e test profile spins up an `owm-stub:8081` service to keep tests deterministic and avoid rate-limiting, but the stub cannot intercept calls when the base URL is baked into source.

## Outcome

- The base URL is resolvable from `import.meta.env.VITE_OWM_BASE_URL` at call time.
- Default behavior (unset env var) preserves today's production endpoint.
- The e2e profile sets `VITE_OWM_BASE_URL=http://owm-stub:8081/data/2.5` at build time and weather calls hit the stub.

## Scope

### Included
- Reading `VITE_OWM_BASE_URL` (default `https://api.openweathermap.org/data/2.5`) inside `getWeatherData`.
- Adding the entry to `.env.example` and `src/vite-env.d.ts`.

### Excluded
- Any change to error handling, caching, or response shape.
- Touching the API key (AZ-448 covers it).

## Acceptance Criteria

**AC-1: Default endpoint preserved**
Given `VITE_OWM_BASE_URL` is unset at build time,
When `getWeatherData(lat, lon)` is invoked,
Then the fetch target hostname is `api.openweathermap.org`.

**AC-2: Override honored**
Given `VITE_OWM_BASE_URL=http://owm-stub:8081/data/2.5` at build time,
When `getWeatherData(lat, lon)` is invoked,
Then the fetch target URL begins with `http://owm-stub:8081/data/2.5/weather?lat=...`.

**AC-3: Type declaration**
Given a TypeScript build,
When the env interface resolves,
Then `ImportMetaEnv` declares `readonly VITE_OWM_BASE_URL: string | undefined`.

## Blackbox Tests

| AC Ref | Initial Data / Conditions | What to Test | Expected Behavior | NFR References |
|--------|--------------------------|--------------|-------------------|----------------|
| AC-1   | env unset; `getWeatherData(0, 0)` called | Outbound URL host | `api.openweathermap.org` | Compat |
| AC-2   | env set to stub; `getWeatherData(0, 0)` called | Outbound URL prefix | Matches stub URL | E2E determinism |
| AC-3   | Build run | `vite-env.d.ts` declaration present | Pass | Compat |

## Constraints

- Land in one commit with AZ-448 to keep the file's mid-state coherent.
- Must not break the (unset-env) production behavior.

## Risks & Mitigation

**Risk 1: Trailing-slash drift**
- *Risk*: A consumer might set the env to `https://host/` and the path concatenation produces `//weather`.
- *Mitigation*: Normalize by trimming a trailing slash before concatenation; document the rule in `.env.example`.
