fix redirect 2nd time
Build & Deploy / Build & Push Docker Image (push) Successful in 2m55s
Test / Type Check (all packages) (push) Successful in 53s
Build & Deploy / Deploy to VPS (push) Successful in 3s
Test / API Unit Tests (push) Successful in 46s
Test / Homepage Unit Tests (push) Successful in 44s
Test / Carplace Unit Tests (push) Successful in 40s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 41s
Test / API Integration Tests (push) Successful in 1m0s
Build & Deploy / Build & Push Docker Image (push) Successful in 2m55s
Test / Type Check (all packages) (push) Successful in 53s
Build & Deploy / Deploy to VPS (push) Successful in 3s
Test / API Unit Tests (push) Successful in 46s
Test / Homepage Unit Tests (push) Successful in 44s
Test / Carplace Unit Tests (push) Successful in 40s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 41s
Test / API Integration Tests (push) Successful in 1m0s
This commit is contained in:
@@ -4,12 +4,34 @@ export function normalizeApiBase(value: string): string {
|
||||
return /\/api\/v1$/.test(base) ? base : `${base}/api/v1`
|
||||
}
|
||||
|
||||
export function resolveApiBase(): string {
|
||||
const value = typeof window === 'undefined'
|
||||
? (process.env.API_INTERNAL_URL || 'http://localhost:4000/api/v1')
|
||||
: (process.env.NEXT_PUBLIC_API_URL || '/dashboard/api/v1')
|
||||
const DASHBOARD_PROXY_API_BASE = '/dashboard/api/v1'
|
||||
|
||||
return normalizeApiBase(value)
|
||||
function isLocalBrowserHost(hostname: string): boolean {
|
||||
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1'
|
||||
}
|
||||
|
||||
function shouldUseDashboardProxy(configuredApiBase?: string): boolean {
|
||||
if (typeof window === 'undefined') return false
|
||||
if (!configuredApiBase) return true
|
||||
if (configuredApiBase.startsWith('/')) return false
|
||||
|
||||
const currentHostname = window.location?.hostname
|
||||
if (!currentHostname || isLocalBrowserHost(currentHostname)) return false
|
||||
|
||||
try {
|
||||
return new URL(configuredApiBase).hostname !== currentHostname
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveApiBase(): string {
|
||||
if (typeof window === 'undefined') {
|
||||
return normalizeApiBase(process.env.API_INTERNAL_URL || 'http://localhost:4000/api/v1')
|
||||
}
|
||||
|
||||
const configuredApiBase = process.env.NEXT_PUBLIC_API_URL
|
||||
return normalizeApiBase(shouldUseDashboardProxy(configuredApiBase) ? DASHBOARD_PROXY_API_BASE : (configuredApiBase || DASHBOARD_PROXY_API_BASE))
|
||||
}
|
||||
|
||||
export const API_BASE = resolveApiBase()
|
||||
|
||||
Reference in New Issue
Block a user