Vercel preview deployments tem hostname tipo reserva-chatmotel-xxx.vercel.app que era interpretado como slug de tenant, causando 'tenant nao encontrado'. Agora qualquer host .vercel.app cai no VITE_DEFAULT_TENANT_SLUG, igual ngrok. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
875 B
TypeScript
31 lines
875 B
TypeScript
// Resolve o tenant slug a partir do hostname.
|
|
// Prod: https://prime.reserva.fazer.ai → slug = "prime"
|
|
// Dev: http://localhost:5180 → fallback VITE_DEFAULT_TENANT_SLUG
|
|
// Cloudflared tunnel: *.trycloudflare.com → fallback VITE_DEFAULT_TENANT_SLUG
|
|
|
|
export function resolveTenantSlug(): string {
|
|
const defaultSlug = import.meta.env.VITE_DEFAULT_TENANT_SLUG || 'grupo-1001'
|
|
|
|
if (typeof window === 'undefined') {
|
|
return defaultSlug
|
|
}
|
|
|
|
const host = window.location.hostname
|
|
|
|
if (host === 'localhost' || host.startsWith('127.') || host.endsWith('.local')) {
|
|
return defaultSlug
|
|
}
|
|
|
|
if (
|
|
host.endsWith('.trycloudflare.com') ||
|
|
host.endsWith('.loca.lt') ||
|
|
host.endsWith('.ngrok-free.dev') ||
|
|
host.endsWith('.vercel.app')
|
|
) {
|
|
return defaultSlug
|
|
}
|
|
|
|
const parts = host.split('.')
|
|
return parts[0] || defaultSlug
|
|
}
|