Files
sionrui/frontend/config/api.js
2026-03-02 01:32:02 +08:00

69 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 公共 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