Voeg VITE_API_BASE_URL toe voor lokale API-calls naar een losse backend
Continuous Integration / config (pull_request) Successful in 10s
Continuous Integration / prepare (pull_request) Successful in 1m21s
Continuous Integration / build-production (pull_request) Skipped
Continuous Integration / build (pull_request) Successful in 2m3s
Continuous Integration / test (pull_request) Successful in 2m14s
Continuous Integration / deploy-production (pull_request) Skipped
Deploy / deploy (pull_request) Successful in 36s
Continuous Integration / deploy-test (pull_request) Successful in 37s

Lokaal (.env.local, niet gecommit) kan VITE_API_BASE_URL op
https://localhost:7223 gezet worden zodat /api/v1/... calls naar een
lokaal draaiende backend gaan i.p.v. hetzelfde origin. Op test/productie
blijft de variabele ongezet, dus blijven calls relatief zoals voorheen.
This commit is contained in:
2026-08-02 15:49:09 +02:00
parent 64cbbac30f
commit 38947ccc20
4 changed files with 23 additions and 3 deletions
@@ -5,10 +5,16 @@ import type { PackageCardData } from '../data/content';
// (test.slpsoftware.nl / slpsoftware.nl) — see aidlc-docs/features/react-frontend/
// construction/react-frontend-app/functional-design/packages-api-handoff.md
// for the API contract this endpoint must implement.
const OFFERINGS_ENDPOINT = '/api/v1/offerings';
// VITE_API_BASE_URL is only set locally (.env.local, e.g. https://localhost:7223) to
// point at a locally running backend; on test/production it's unset, so the path stays
// relative to whichever origin served the app. Read inside the function (not as a
// module-level constant) so tests can stub it per-case.
function offeringsEndpoint() {
return `${import.meta.env.VITE_API_BASE_URL ?? ''}/api/v1/offerings`;
}
async function fetchPackages(): Promise<PackageCardData[]> {
const response = await fetch(OFFERINGS_ENDPOINT);
const response = await fetch(offeringsEndpoint());
if (!response.ok) {
throw new Error(`Failed to fetch packages: ${response.status} ${response.statusText}`);
}