Files
FitOS/admin/src/config.ts

30 lines
995 B
TypeScript

/// <reference types="vite/client" />
declare global {
interface Window {
__FITOS_CONFIG__?: { apiUrl?: string; appUrl?: string };
}
}
export const API_URL: string =
window.__FITOS_CONFIG__?.apiUrl ||
(import.meta.env.VITE_API_URL as string | undefined) ||
window.location.origin;
export const API_BASE = `${API_URL}/api/v1`;
/**
* Origin aplikacji użytkownika (link „Aplikacja" w menu panelu).
* config.js: `appUrl` (pełny adres) ma pierwszeństwo. Fallback: ten sam host,
* port aplikacji wg znanego mapowania stosów (dev 9000→9001, vite 5174→5173,
* staging 13000→13001). Własne mapowanie portów (prod) = wpis w config.js.
*/
export const APP_URL: string =
window.__FITOS_CONFIG__?.appUrl ||
(() => {
const { protocol, hostname, port } = window.location;
const appPort =
port === '9000' ? '9001' : port === '5174' ? '5173' : port === '13000' ? '13001' : port;
return `${protocol}//${hostname}${appPort ? `:${appPort}` : ''}`;
})();