diff --git a/src/app/api.ts b/src/app/api.ts index 56ecaf9..c84a6a0 100644 --- a/src/app/api.ts +++ b/src/app/api.ts @@ -1,6 +1,30 @@ import { isDevMode } from '@angular/core'; -// QR Vitanova API (dynamic QR, settings, polling). +export function resolveProductionApiBase( + hostname: string = globalThis.location?.hostname ?? '' +): string { + + if (!hostname) { + return 'https://qr.vitanova.network/api'; + } + + // If app is already on qr., use the same host. + if (hostname.startsWith('qr.')) { + return `https://${hostname}/api`; + } + + // For domains like app.paylow.online or paylow.online, target qr.paylow.online. + const parts = hostname.split('.').filter(Boolean); + if (parts.length >= 2) { + const rootDomain = parts.slice(-2).join('.'); + return `https://qr.${rootDomain}/api`; + } + + return `https://qr.${hostname}/api`; +} + +// Dynamic QR API base (settings, creation, polling). +// Dev keeps proxy for local work; production resolves from the current domain. export const QR_VITANOVA_API = isDevMode() ? '/proxy/qr-vitanova/api' - : 'https://qr.vitanova.network/api'; + : resolveProductionApiBase();