feat: 功能
This commit is contained in:
51
frontend/config/api.js
Normal file
51
frontend/config/api.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 公共 API 基础配置
|
||||
* 统一管理所有 API 的基础 URL
|
||||
* 可在各个应用中通过 @gold/config/api 引用
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取基础 URL(从环境变量读取)
|
||||
* @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}`,
|
||||
// 具体模块路径
|
||||
ADMIN_AI: `${BASE_URL}/admin-api/ai`,
|
||||
APP_MEMBER: `${BASE_URL}/app-api/member`,
|
||||
|
||||
// 特殊路径
|
||||
TIKHUB_APP: `${BASE_URL}/api/tikHup`,
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整的 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 : '/' + path}`
|
||||
}
|
||||
|
||||
export default API_BASE
|
||||
|
||||
Reference in New Issue
Block a user