From 3aac87de508b1814c87454142089d99a2c699f9e Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 30 Oct 2025 12:36:57 +0100 Subject: [PATCH] Fix API_BASE_URL to use runtime configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL FIX: Checkout was failing because API calls went to localhost The checkoutClient was hardcoded to use import.meta.env.VITE_API_BASE_URL which is build-time only. In production, this defaulted to localhost:3001 instead of the actual backend URL. Changed to read from window.env.API_BASE_URL (runtime config) first, then fall back to build-time config. This matches the pattern used in src/utils/config.ts. Frontend will now correctly connect to: - Development: http://localhost:3001 - Production: https://puffinoffset.com/api (from .env file) Fixes network error: "Failed to fetch" when creating checkout session 🔒 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/api/checkoutClient.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/api/checkoutClient.ts b/src/api/checkoutClient.ts index cfdd652..4a83b55 100644 --- a/src/api/checkoutClient.ts +++ b/src/api/checkoutClient.ts @@ -1,7 +1,18 @@ import axios from 'axios'; import { logger } from '../utils/logger'; -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3001'; +// Get API base URL from runtime config (window.env) or build-time config +const getApiBaseUrl = (): string => { + // Check window.env first (runtime config from env.sh) + if (typeof window !== 'undefined' && window.env?.API_BASE_URL) { + return window.env.API_BASE_URL; + } + + // Fall back to build-time env or default + return import.meta.env.VITE_API_BASE_URL || 'http://localhost:3001'; +}; + +const API_BASE_URL = getApiBaseUrl(); export interface CreateCheckoutSessionParams { tons: number;