Files
smart-crop-ui/crop-x/src/lib/api/config.ts

37 lines
1.0 KiB
TypeScript
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.

/**
* filekorolheader: API配置文件 - API客户端配置和认证处理
* 功能API基础配置、认证头部处理、错误处理
* 路径:/lib/api/config
* 规范遵循crop-x/docs/开发项目规范.md统一API调用配置
*/
import { getAuthToken } from '@/utils/token';
// API基础URL配置 - 开发环境直接使用真实API地址避免重定向问题
export const API_BASE_URL = 'https://gitea-admin-hm-smart-agri-app.dev.maimaiag.com';
// 获取认证头部
export const getAuthHeaders = () => {
const token = getAuthToken();
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'Accept': 'application/json',
// 添加缓存控制头部
'Cache-Control': 'no-store, no-cache, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
return headers;
};
// API请求配置
export const apiConfig = {
baseURL: API_BASE_URL,
timeout: 30000, // 30秒超时
headers: getAuthHeaders(),
};