refactor(api): use absolute production URLs for all API calls instead of local proxy
parent
3bae006887
commit
c03e54867f
43
src/api.ts
43
src/api.ts
|
|
@ -4,7 +4,7 @@ const AURA_API_BASE = 'https://api.redhare.cc/aura/v1';
|
|||
const isMockAuth = () => typeof localStorage !== 'undefined' && localStorage.getItem('mock-auth') === '1';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: '/api',
|
||||
baseURL: 'https://api.redhare.cc/aura/v1',
|
||||
timeout: 90000,
|
||||
withCredentials: true // 关键:跨域请求带 cookie
|
||||
});
|
||||
|
|
@ -366,15 +366,16 @@ export interface AuthUser {
|
|||
|
||||
export const AuthAPI = {
|
||||
me: () => api.get<AuthUser>('/auth/me').then((r) => r.data),
|
||||
verify: (email: string, password: string) =>
|
||||
axios
|
||||
.post(
|
||||
`${AURA_API_BASE}/urser`,
|
||||
{ email, password },
|
||||
{ timeout: 90000, withCredentials: true }
|
||||
)
|
||||
.then(() => true)
|
||||
.catch(() => true),
|
||||
verify: async (email: string, password: string) => {
|
||||
// 根据要求,这里直接请求真实地址,未启动时 mock 返回 true
|
||||
try {
|
||||
const res = await axios.post('https://api.redhare.cc/aura/v1/urser', { email, password }, { timeout: 3000 });
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
console.warn('Backend /urser not available, fallback to mock true', e);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
login: (email: string, password: string) =>
|
||||
api.post<AuthUser>('/auth/login', { email, password }).then((r) => r.data),
|
||||
register: (payload: { email: string; password: string; name: string; inviteCode?: string }) =>
|
||||
|
|
@ -532,40 +533,46 @@ export interface ModelOverrides {
|
|||
export async function streamChat(
|
||||
agentId: string,
|
||||
content: string,
|
||||
h: StreamEvents,
|
||||
handlers: StreamEvents,
|
||||
signal?: AbortSignal,
|
||||
sessionId?: string,
|
||||
overrides?: ModelOverrides,
|
||||
attachmentsText?: 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',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ content, sessionId, overrides, attachmentsText, imageUrls }),
|
||||
body: JSON.stringify({
|
||||
content,
|
||||
sessionId,
|
||||
overrides,
|
||||
attachmentsText,
|
||||
imageUrls
|
||||
}),
|
||||
signal,
|
||||
credentials: 'include'
|
||||
});
|
||||
return await consumeSSE(resp, h, signal);
|
||||
return await consumeSSE(resp, handlers, signal);
|
||||
}
|
||||
|
||||
/** 重新生成(开新分支);行为同 streamChat */
|
||||
export async function regenerateMessage(
|
||||
agentId: string,
|
||||
assistantMsgId: string,
|
||||
h: StreamEvents,
|
||||
messageId: string,
|
||||
handlers: StreamEvents,
|
||||
signal?: AbortSignal,
|
||||
overrides?: ModelOverrides,
|
||||
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',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ overrides, attachmentsText }),
|
||||
signal,
|
||||
credentials: 'include'
|
||||
});
|
||||
return await consumeSSE(resp, h, signal);
|
||||
return await consumeSSE(resp, handlers, signal);
|
||||
}
|
||||
|
||||
async function consumeSSE(resp: Response, h: StreamEvents, signal?: AbortSignal) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue