refactor(api): use absolute production URLs for all API calls instead of local proxy

main
sp mac bookpro 2605 2026-05-24 20:01:52 +08:00
parent 3bae006887
commit c03e54867f
1 changed files with 25 additions and 18 deletions

View File

@ -4,7 +4,7 @@ const AURA_API_BASE = 'https://api.redhare.cc/aura/v1';
const isMockAuth = () => typeof localStorage !== 'undefined' && localStorage.getItem('mock-auth') === '1'; const isMockAuth = () => typeof localStorage !== 'undefined' && localStorage.getItem('mock-auth') === '1';
export const api = axios.create({ export const api = axios.create({
baseURL: '/api', baseURL: 'https://api.redhare.cc/aura/v1',
timeout: 90000, timeout: 90000,
withCredentials: true // 关键:跨域请求带 cookie withCredentials: true // 关键:跨域请求带 cookie
}); });
@ -366,15 +366,16 @@ export interface AuthUser {
export const AuthAPI = { export const AuthAPI = {
me: () => api.get<AuthUser>('/auth/me').then((r) => r.data), me: () => api.get<AuthUser>('/auth/me').then((r) => r.data),
verify: (email: string, password: string) => verify: async (email: string, password: string) => {
axios // 根据要求,这里直接请求真实地址,未启动时 mock 返回 true
.post( try {
`${AURA_API_BASE}/urser`, const res = await axios.post('https://api.redhare.cc/aura/v1/urser', { email, password }, { timeout: 3000 });
{ email, password }, return res.data;
{ timeout: 90000, withCredentials: true } } catch (e) {
) console.warn('Backend /urser not available, fallback to mock true', e);
.then(() => true) return true;
.catch(() => true), }
},
login: (email: string, password: string) => login: (email: string, password: string) =>
api.post<AuthUser>('/auth/login', { email, password }).then((r) => r.data), api.post<AuthUser>('/auth/login', { email, password }).then((r) => r.data),
register: (payload: { email: string; password: string; name: string; inviteCode?: string }) => register: (payload: { email: string; password: string; name: string; inviteCode?: string }) =>
@ -532,40 +533,46 @@ export interface ModelOverrides {
export async function streamChat( export async function streamChat(
agentId: string, agentId: string,
content: string, content: string,
h: StreamEvents, handlers: StreamEvents,
signal?: AbortSignal, signal?: AbortSignal,
sessionId?: string, sessionId?: string,
overrides?: ModelOverrides, overrides?: ModelOverrides,
attachmentsText?: string, attachmentsText?: string,
imageUrls?: string[] imageUrls?: string[]
) { ) {
const resp = await fetch(`/api/chat/${agentId}/messages/stream`, { const resp = await fetch(`https://api.redhare.cc/aura/v1/chat/${agentId}/messages/stream`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content, sessionId, overrides, attachmentsText, imageUrls }), body: JSON.stringify({
content,
sessionId,
overrides,
attachmentsText,
imageUrls
}),
signal, signal,
credentials: 'include' credentials: 'include'
}); });
return await consumeSSE(resp, h, signal); return await consumeSSE(resp, handlers, signal);
} }
/** 重新生成(开新分支);行为同 streamChat */ /** 重新生成(开新分支);行为同 streamChat */
export async function regenerateMessage( export async function regenerateMessage(
agentId: string, agentId: string,
assistantMsgId: string, messageId: string,
h: StreamEvents, handlers: StreamEvents,
signal?: AbortSignal, signal?: AbortSignal,
overrides?: ModelOverrides, overrides?: ModelOverrides,
attachmentsText?: string attachmentsText?: string
) { ) {
const resp = await fetch(`/api/chat/${agentId}/messages/${assistantMsgId}/regenerate`, { const resp = await fetch(`https://api.redhare.cc/aura/v1/chat/${agentId}/messages/${messageId}/regenerate`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ overrides, attachmentsText }), body: JSON.stringify({ overrides, attachmentsText }),
signal, signal,
credentials: 'include' credentials: 'include'
}); });
return await consumeSSE(resp, h, signal); return await consumeSSE(resp, handlers, signal);
} }
async function consumeSSE(resp: Response, h: StreamEvents, signal?: AbortSignal) { async function consumeSSE(resp: Response, h: StreamEvents, signal?: AbortSignal) {