diff --git a/ui/homepage/app/api/askai/route.ts b/ui/homepage/app/api/askai/route.ts index 20c4114..71f9987 100644 --- a/ui/homepage/app/api/askai/route.ts +++ b/ui/homepage/app/api/askai/route.ts @@ -1,8 +1,8 @@ -import { getServerServiceBaseUrl } from '@lib/serviceConfig' +import { getInternalServerServiceBaseUrl } from '@lib/serviceConfig' export async function POST(req: Request) { const { question, history } = await req.json() - const apiBase = getServerServiceBaseUrl() + const apiBase = getInternalServerServiceBaseUrl() const res = await fetch(`${apiBase}/api/askai`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/ui/homepage/app/api/rag/query/route.ts b/ui/homepage/app/api/rag/query/route.ts index 3274d87..ebeaf6d 100644 --- a/ui/homepage/app/api/rag/query/route.ts +++ b/ui/homepage/app/api/rag/query/route.ts @@ -1,9 +1,9 @@ -import { getServerServiceBaseUrl } from '@lib/serviceConfig' +import { getInternalServerServiceBaseUrl } from '@lib/serviceConfig' export async function POST(req: Request) { try { const { question, history } = await req.json() - const apiBase = getServerServiceBaseUrl() + const apiBase = getInternalServerServiceBaseUrl() const response = await fetch(`${apiBase}/api/rag/query`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/ui/homepage/lib/serviceConfig.ts b/ui/homepage/lib/serviceConfig.ts index 070d9aa..b63000c 100644 --- a/ui/homepage/lib/serviceConfig.ts +++ b/ui/homepage/lib/serviceConfig.ts @@ -69,6 +69,7 @@ type ServiceKey = keyof EnvironmentRuntimeConfig const FALLBACK_ACCOUNT_SERVICE_URL = 'http://localhost:8080' const FALLBACK_SERVER_SERVICE_URL = 'http://localhost:8090' +const FALLBACK_SERVER_SERVICE_INTERNAL_URL = 'http://127.0.0.1:8090' const LOCAL_HOSTNAMES = new Set(['localhost', '127.0.0.1', '[::1]']) @@ -199,6 +200,32 @@ export function getServerServiceBaseUrl(): string { return normalizeBaseUrl(configured ?? DEFAULT_SERVER_SERVICE_URL) } +const SERVER_INTERNAL_URL_ENV_KEYS = [ + 'SERVER_SERVICE_INTERNAL_URL', + 'SERVER_INTERNAL_URL', + 'INTERNAL_SERVER_SERVICE_URL', +] as const + +export function getInternalServerServiceBaseUrl(): string { + const configured = readEnvValue(...SERVER_INTERNAL_URL_ENV_KEYS) + if (configured) { + return normalizeBaseUrl(configured) + } + + const external = getServerServiceBaseUrl() + + try { + const parsed = new URL(external) + if (LOCAL_HOSTNAMES.has(parsed.hostname)) { + return normalizeBaseUrl(external) + } + } catch { + // Ignore parsing errors and fall back to the internal default below. + } + + return normalizeBaseUrl(FALLBACK_SERVER_SERVICE_INTERNAL_URL) +} + export const serviceConfig = { account: { baseUrl: getAccountServiceBaseUrl(),