69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
/**
|
||
* 公共 API 基础配置
|
||
* 统一管理所有 API 的基础 URL
|
||
* 可在各个应用中通过 @gold/config/api 引用
|
||
*/
|
||
|
||
/**
|
||
* 获取基础 URL(从环境变量读取)/webApi
|
||
* @returns {string}
|
||
*/
|
||
function getBaseUrl() {
|
||
// 支持在浏览器环境和 Node 环境
|
||
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
||
return import.meta.env.VITE_BASE_URL || ''
|
||
}
|
||
// 如果是在 Node 环境或 SSR,可以从 process.env 读取
|
||
if (typeof process !== 'undefined' && process.env) {
|
||
return process.env.VITE_BASE_URL || ''
|
||
}
|
||
return ''
|
||
}
|
||
|
||
const BASE_URL = getBaseUrl()
|
||
|
||
/**
|
||
* API 基础路径配置
|
||
*/
|
||
export const API_BASE = {
|
||
// 会员端 API
|
||
APP: `${BASE_URL}`,
|
||
// 具体模块路径
|
||
APP_AI: `${BASE_URL}/api/ai`,
|
||
APP_MEMBER: `${BASE_URL}/app-api/member`,
|
||
APP_TIK: `${BASE_URL}/api/tik`, // Tik 模块 API
|
||
|
||
// 特殊路径
|
||
TIKHUB_APP: `${BASE_URL}/api/tikHup`,
|
||
AI_APP: `${BASE_URL}/api/ai`,
|
||
}
|
||
|
||
/**
|
||
* OSS 原始域名(用于上传预签名URL代理)
|
||
*/
|
||
export const OSS_ORIGINAL = 'https://muye-ai-chat.oss-cn-hangzhou.aliyuncs.com'
|
||
|
||
/**
|
||
* 判断是否为开发环境
|
||
*/
|
||
export const isDev = () => {
|
||
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
||
return import.meta.env.DEV
|
||
}
|
||
return false
|
||
}
|
||
|
||
/**
|
||
* 获取完整的 API 路径
|
||
* @param {string} module - 模块名称 (如 'ADMIN_AI', 'APP_MEMBER')
|
||
* @param {string} path - 接口路径 (如 '/chat/conversation/create-my')
|
||
* @returns {string} 完整的 API URL
|
||
*/
|
||
export function getApiUrl(module, path) {
|
||
const base = API_BASE[module] || API_BASE.APP
|
||
return `${base}${path.startsWith('/') ? '' : '/'}${path}`
|
||
}
|
||
|
||
export default API_BASE
|
||
|