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

54 lines
1.4 KiB
JavaScript

import { getLegacyBaseUrl } from './legacyUrls.js';
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();
}
function resolveLegacyAssetBaseUrl() {
const configuredAssetBaseUrl = trimTrailingSlash(import.meta.env.VITE_LEGACY_ASSET_BASE_URL || '');
if (configuredAssetBaseUrl) {
return configuredAssetBaseUrl;
}
if (localHostnames.has(currentHostname())) {
return '/legacy-static';
}
return getLegacyBaseUrl();
}
const legacyAssetBaseUrl = resolveLegacyAssetBaseUrl();
export function legacyAsset(path) {
return `${legacyAssetBaseUrl}${path.startsWith('/') ? path : `/${path}`}`;
}
export function injectLegacyStylesheets() {
const stylesheets = [
legacyAsset('/vendor/bootstrap/css/bootstrap.min.css'),
'https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i',
legacyAsset('/css/custom-style.css')
];
stylesheets.forEach((href) => {
if (document.head.querySelector(`link[data-legacy-href="${href}"]`)) {
return;
}
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = href;
link.dataset.legacyHref = href;
document.head.appendChild(link);
});
}