Regalamiunsorriso/faceai/apps/frontend/src/legacyUrls.js

29 lines
817 B
JavaScript

const localHostnames = new Set(['localhost', '127.0.0.1', '::1']);
function trimTrailingSlash(value) {
return String(value || '').replace(/\/$/, '');
}
function currentHostname() {
if (typeof window === 'undefined' || !window.location || !window.location.hostname) {
return '';
}
return window.location.hostname.toLowerCase();
}
export function getLegacyBaseUrl() {
const configuredBaseUrl = trimTrailingSlash(import.meta.env.VITE_LEGACY_BASE_URL || '');
if (configuredBaseUrl) {
return configuredBaseUrl;
}
return localHostnames.has(currentHostname())
? 'http://localhost:8080'
: 'https://www.regalamiunsorriso.it';
}
export function legacyUrl(path = '/') {
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
return `${getLegacyBaseUrl()}${normalizedPath}`;
}