sjdkadbksjdkadbk

This commit is contained in:
Hymmel 2025-10-09 09:42:00 +02:00
parent e7c0f9f334
commit 4974e7d6f3

View file

@ -7,7 +7,21 @@ const defaultApiBase =
? 'https://backend.basetracker.lona-development.org'
: 'http://localhost:4100';
const API_BASE = process.env.NEXT_PUBLIC_BACKEND_URL ?? defaultApiBase;
// Normalize backend URL so production always uses HTTPS while keeping local HTTP.
function normalizeApiBase(url: string) {
try {
const parsed = new URL(url);
const isLocalhost = ['localhost', '127.0.0.1', '0.0.0.0'].includes(parsed.hostname);
if (!isLocalhost && parsed.protocol === 'http:') {
parsed.protocol = 'https:';
}
return parsed.toString().replace(/\/$/, '');
} catch (_error) {
return url.replace(/\/$/, '');
}
}
const API_BASE = normalizeApiBase(process.env.NEXT_PUBLIC_BACKEND_URL ?? defaultApiBase);
const API = {
signup: `${API_BASE}/auth/signup`,