const DEFAULT_APP_URL = "https://example.com"; function readEnvironment(name: string, fallback: string): string { return process.env[name]?.trim() || fallback; } function normalizeSiteUrl(value: string | undefined): string { const trimmed = value?.trim(); if (!trimmed) return DEFAULT_APP_URL; try { const normalized = new URL(trimmed); if (!["http:", "https:"].includes(normalized.protocol)) return DEFAULT_APP_URL; normalized.pathname = normalized.pathname.replace(/\/+$/, ""); return normalized.toString().replace(/\/$/, ""); } catch { return DEFAULT_APP_URL; } } export const SITE_NAME = readEnvironment("APP_NAME", "Example Website"); export const SITE_URL = normalizeSiteUrl(process.env.APP_URL); export const COMPANY_NAME = readEnvironment("COMPANY_NAME", "Example Company"); export const CONTACT_EMAIL = readEnvironment("CONTACT_EMAIL", "info@example.com"); export const CONTACT_PHONE = readEnvironment("CONTACT_PHONE", "+49 000 000000"); export const CONTACT_ADDRESS = readEnvironment( "CONTACT_ADDRESS", "Example Street 1, 12345 Example City", ); export function toAbsoluteUrl(pathname: string): string { if (/^https?:\/\//i.test(pathname)) return pathname; const normalized = pathname.startsWith("/") ? pathname : `/${pathname}`; return `${SITE_URL}${normalized}`; } export function toPhoneUrl(phone: string): string { return `tel:${phone.replace(/[^+\d]/g, "")}`; }