mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-28 16:00:57 +00:00
refactor(api): resolve the backend URL in one place
VITE_BASE_API_URL with a localhost:3001/api fallback was re-derived in six files across libs/api, libs/auth, the portal and the backoffice — and a seventh site (UserManagementPage) read the env raw with no fallback at all, handing the IAM user-management app an undefined apiUrl whenever no .env was present. BASE_API_URL in base-query-with-reauth.ts is now the single definition, exported from @ema-platform/api; every other site imports it. Trims the env value and treats blank as unset, matching how the backend reads its own keys.
This commit is contained in:
@@ -7,5 +7,5 @@ export * from './lib/features/seafarer';
|
||||
export * from './lib/features/seafarer-registration';
|
||||
export * from './lib/features/seafarer-document';
|
||||
export * from './lib/features/vessel';
|
||||
export { baseQueryWithReauth, configureTokenRefresh } from './lib/base-api/base-query-with-reauth';
|
||||
export { BASE_API_URL, baseQueryWithReauth, configureTokenRefresh } from './lib/base-api/base-query-with-reauth';
|
||||
export { openAuthedDocument, downloadAuthedFile } from './lib/base-api/download';
|
||||
|
||||
@@ -2,10 +2,15 @@ import { fetchBaseQuery, type BaseQueryFn } from "@reduxjs/toolkit/query/react";
|
||||
import type { FetchArgs, FetchBaseQueryError } from "@reduxjs/toolkit/query";
|
||||
import { resolveSessionContext } from "../session";
|
||||
|
||||
/**
|
||||
* The one place the backend URL is resolved: VITE_BASE_API_URL from the env,
|
||||
* falling back to the local dev API (3001 — the portal itself owns 3000 for
|
||||
* the Fayda redirect). Import this; do not re-derive it.
|
||||
*/
|
||||
export const BASE_API_URL =
|
||||
(import.meta as { env?: Record<string, string> }).env?.[
|
||||
"VITE_BASE_API_URL"
|
||||
] ?? "http://localhost:3001/api";
|
||||
]?.trim() || "http://localhost:3001/api";
|
||||
|
||||
let _onTokenExpired: (() => Promise<string>) | null = null;
|
||||
let _onAuthFailure: (() => void) | null = null;
|
||||
|
||||
@@ -10,9 +10,7 @@ import type {
|
||||
ValidationIssue,
|
||||
} from './licensing.types';
|
||||
|
||||
const BASE_API_URL =
|
||||
(import.meta as { env?: Record<string, string> }).env?.['VITE_BASE_API_URL'] ??
|
||||
'http://localhost:3001/api';
|
||||
import { BASE_API_URL } from '../../base-api/base-query-with-reauth';
|
||||
|
||||
/**
|
||||
* Uploads a document straight to the API.
|
||||
|
||||
Reference in New Issue
Block a user