Fix API_BASE_URL to use runtime configuration
All checks were successful
Build and Push Docker Images / docker (push) Successful in 45s

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 <noreply@anthropic.com>
This commit is contained in:
Matt 2025-10-30 12:36:57 +01:00
parent 0d7ac4b1de
commit 3aac87de50

View File

@ -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;