import axios, { InternalAxiosRequestConfig } from 'axios'; import { getApiBaseUrl } from '../config'; export const BASE_API_URL = getApiBaseUrl(); // Create Axios Instance export const apiClient = axios.create({ baseURL: BASE_API_URL, headers: { 'Content-Type': 'application/json; version=1', Accept: 'application/json; version=1', }, timeout: 15000, }); // Request Interceptor to dynamically set baseURL and attach Bearer Token apiClient.interceptors.request.use( (config: InternalAxiosRequestConfig) => { // Dynamically synchronize baseURL from runtime configuration config.baseURL = getApiBaseUrl(); const token = localStorage.getItem('pfm_access_token'); if (token && config.headers) { config.headers.Authorization = `Bearer ${token}`; } return config; }, (error) => Promise.reject(error) );