fix(frontend): robust runtime config loading in api layer
This commit is contained in:
parent
1eb3da814d
commit
5f5afbaf43
2 changed files with 7 additions and 9 deletions
|
|
@ -51,14 +51,6 @@ export function ConfigProvider({ children }: { children: ReactNode }) {
|
|||
fetchConfig();
|
||||
}, []);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex h-screen w-screen items-center justify-center bg-background">
|
||||
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfigContext.Provider value={{ config, isLoading }}>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { toast } from "sonner";
|
||||
import { Job } from "./types";
|
||||
import { getApiUrl, getBackofficeUrl } from "./config";
|
||||
import { getApiUrl, getBackofficeUrl, initConfig } from "./config";
|
||||
|
||||
// API Base URL - now uses runtime config
|
||||
// Fetched from /api/config at runtime, falls back to build-time env or defaults
|
||||
|
|
@ -16,6 +16,9 @@ function logCrudAction(action: string, entity: string, details?: any) {
|
|||
* Generic API Request Wrapper
|
||||
*/
|
||||
async function apiRequest<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
|
||||
// Ensure config is loaded before making request
|
||||
await initConfig();
|
||||
|
||||
// Token can be stored as 'auth_token' (from auth.ts login) or 'token' (legacy)
|
||||
const token = localStorage.getItem("auth_token") || localStorage.getItem("token");
|
||||
const headers = {
|
||||
|
|
@ -572,6 +575,9 @@ export const profileApi = {
|
|||
// Backoffice URL - now uses runtime config
|
||||
|
||||
async function backofficeRequest<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
|
||||
// Ensure config is loaded before making request
|
||||
await initConfig();
|
||||
|
||||
const token = localStorage.getItem("token");
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
|||
Loading…
Reference in a new issue