Files
juip-web/src/lib/api.ts
2026-08-14 16:30:41 +08:00

25 lines
718 B
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.
// 定义后端服务URL和OAuth2配置
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? ""
const CLIENT_ID = import.meta.env.VITE_CLIENT_ID
if (!CLIENT_ID) throw new Error("VITE_CLIENT_ID is not set")
const CLIENT_SECRET = import.meta.env.VITE_CLIENT_SECRET
if (!CLIENT_SECRET) throw new Error("VITE_CLIENT_SECRET is not set")
// 统一的API响应类型
type ApiResponse<T = undefined> =
| {
success: false
status?: number
message: string
}
| {
success: true
data: T
// 响应头key 统一小写),用于登录等场景从 header 取数据
headers?: Record<string, string>
}
export { API_BASE_URL, type ApiResponse, CLIENT_ID, CLIENT_SECRET }