Files
workspace/code/container-ocr/ocr-uniapp/src/utils/request.ts
T
2026-03-18 17:29:39 +08:00

29 lines
833 B
TypeScript

export function getServerBaseUrl(): string {
const origin = window.location.origin
const publicBase = import.meta.env.VITE_APP_PUBLIC_BASE || '/'
// 拼接时去掉 publicBase 开头和结尾的斜杠(只保留中间路径)
const cleanBase = publicBase.replace(/^\/+|\/+$/g, '')
return cleanBase ? `${origin}/${cleanBase}` : origin
}
export async function getDbConfigs(): Promise<Record<string, any> | null> {
const serverBaseUrl = getServerBaseUrl()
try {
const response = await fetch(`${serverBaseUrl}/static/db.json`)
if (!response.ok) {
console.error('Failed to fetch db.json:', response.status)
return null
}
const data: Record<string, any> = await response.json()
return data
}
catch (error) {
console.error('Error fetching db.json:', error)
return null
}
}