chore: centralize service endpoints configuration (#328)
This commit is contained in:
parent
706de5c2fd
commit
a15a2eb88f
@ -1,6 +1,8 @@
|
||||
import { getServerServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { question, history } = await req.json()
|
||||
const apiBase = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080'
|
||||
const apiBase = getServerServiceBaseUrl()
|
||||
const res = await fetch(`${apiBase}/api/askai`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = process.env.ACCOUNT_SERVICE_URL || 'http://localhost:8080'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const SESSION_COOKIE_NAME = 'account_session'
|
||||
|
||||
async function authenticateWithAccountService(email: string, password: string) {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = process.env.ACCOUNT_SERVICE_URL || 'http://localhost:8080'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
|
||||
async function registerWithAccountService(body: Record<string, string>) {
|
||||
try {
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import { cookies } from 'next/headers'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = process.env.ACCOUNT_SERVICE_URL || 'http://localhost:8080'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const SESSION_COOKIE_NAME = 'account_session'
|
||||
|
||||
type AccountUser = {
|
||||
|
||||
@ -3,11 +3,12 @@
|
||||
import { useState } from 'react'
|
||||
import { Bot } from 'lucide-react'
|
||||
import { AskAIDialog } from './AskAIDialog'
|
||||
import { getServerServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
export function AskAIButton() {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [minimized, setMinimized] = useState(false)
|
||||
const apiBase = process.env.NEXT_PUBLIC_API_BASE_URL || ''
|
||||
const apiBase = getServerServiceBaseUrl()
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { getServerServiceBaseUrl } from './serviceConfig'
|
||||
|
||||
export async function fetchRelatedDocs(query: string): Promise<string[]> {
|
||||
const apiBase = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080'
|
||||
const apiBase = getServerServiceBaseUrl()
|
||||
try {
|
||||
const res = await fetch(`${apiBase}/api/rag/query`, {
|
||||
method: 'POST',
|
||||
|
||||
42
ui/homepage/lib/serviceConfig.ts
Normal file
42
ui/homepage/lib/serviceConfig.ts
Normal file
@ -0,0 +1,42 @@
|
||||
const DEFAULT_ACCOUNT_SERVICE_URL = 'http://localhost:8080'
|
||||
const DEFAULT_SERVER_SERVICE_URL = 'http://localhost:8090'
|
||||
|
||||
function readEnvValue(...keys: string[]): string | undefined {
|
||||
for (const key of keys) {
|
||||
const raw = process.env[key]
|
||||
if (typeof raw === 'string') {
|
||||
const trimmed = raw.trim()
|
||||
if (trimmed.length > 0) {
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function normalizeBaseUrl(baseUrl: string): string {
|
||||
return baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl
|
||||
}
|
||||
|
||||
export function getAccountServiceBaseUrl(): string {
|
||||
const configured = readEnvValue('ACCOUNT_SERVICE_URL', 'NEXT_PUBLIC_ACCOUNT_SERVICE_URL')
|
||||
return normalizeBaseUrl(configured ?? DEFAULT_ACCOUNT_SERVICE_URL)
|
||||
}
|
||||
|
||||
export function getServerServiceBaseUrl(): string {
|
||||
const configured = readEnvValue(
|
||||
'SERVER_SERVICE_URL',
|
||||
'NEXT_PUBLIC_SERVER_SERVICE_URL',
|
||||
'NEXT_PUBLIC_API_BASE_URL',
|
||||
)
|
||||
return normalizeBaseUrl(configured ?? DEFAULT_SERVER_SERVICE_URL)
|
||||
}
|
||||
|
||||
export const serviceConfig = {
|
||||
account: {
|
||||
baseUrl: getAccountServiceBaseUrl(),
|
||||
},
|
||||
server: {
|
||||
baseUrl: getServerServiceBaseUrl(),
|
||||
},
|
||||
} as const
|
||||
Loading…
Reference in New Issue
Block a user