WIP - BFF
This commit is contained in:
39
frontend/server/utils/tenant.ts
Normal file
39
frontend/server/utils/tenant.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { getHeader } from 'h3'
|
||||
|
||||
/**
|
||||
* Extract subdomain from the request Host header
|
||||
* Handles production domains (tenant1.routebox.co) and development (tenant1.localhost)
|
||||
*/
|
||||
export function getSubdomainFromRequest(event: H3Event): string | null {
|
||||
const host = getHeader(event, 'host') || ''
|
||||
const hostname = host.split(':')[0] // Remove port if present
|
||||
|
||||
const parts = hostname.split('.')
|
||||
|
||||
// For production domains with 3+ parts (e.g., tenant1.routebox.co)
|
||||
if (parts.length >= 3) {
|
||||
const subdomain = parts[0]
|
||||
// Ignore www subdomain
|
||||
if (subdomain === 'www') {
|
||||
return null
|
||||
}
|
||||
return subdomain
|
||||
}
|
||||
|
||||
// For development (e.g., tenant1.localhost)
|
||||
if (parts.length === 2 && parts[1] === 'localhost') {
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the subdomain is a central/admin subdomain
|
||||
*/
|
||||
export function isCentralSubdomain(subdomain: string | null): boolean {
|
||||
if (!subdomain) return false
|
||||
const centralSubdomains = (process.env.CENTRAL_SUBDOMAINS || 'central,admin').split(',')
|
||||
return centralSubdomains.includes(subdomain)
|
||||
}
|
||||
Reference in New Issue
Block a user