| |
| |
| |
| |
| import URLHandler from '../core/URLHandler'; |
|
|
| export const INFORADAR_API_BASE_META_NAME = 'inforadar-api-base'; |
|
|
| export function normalizeApiBase(url: string): string { |
| const s = url.trim(); |
| if (!s) return ''; |
| return s.replace(/\/+$/, ''); |
| } |
|
|
| |
| export function resolveApiBaseFromSources(apiParam: unknown, metaContent: string | null | undefined): string { |
| const fromMeta = metaContent?.trim(); |
| if (fromMeta) return normalizeApiBase(fromMeta); |
| if (apiParam !== undefined && apiParam !== null) { |
| const fromParam = String(apiParam).trim(); |
| if (fromParam) return normalizeApiBase(fromParam); |
| } |
| return ''; |
| } |
|
|
| export function resolveApiBase(): string { |
| const meta = |
| typeof document !== 'undefined' |
| ? document.querySelector(`meta[name="${INFORADAR_API_BASE_META_NAME}"]`)?.getAttribute('content') |
| : null; |
| return resolveApiBaseFromSources(URLHandler.parameters['api'], meta); |
| } |
|
|
| |
| |
| |
| |
| export function apiUrl(path: string, apiBase?: string): string { |
| const base = apiBase !== undefined ? normalizeApiBase(apiBase) : resolveApiBase(); |
| const normalized = path.startsWith('/') ? path : `/${path}`; |
| return `${base}${normalized}`; |
| } |
|
|