30 lines
856 B
TypeScript
30 lines
856 B
TypeScript
import axios from 'axios';
|
|
import { i18n } from './locales';
|
|
|
|
const instance = axios.create({ baseURL: '/api', timeout: 20000 });
|
|
|
|
instance.interceptors.request.use((config) => {
|
|
config.headers = config.headers ?? {};
|
|
config.headers['Accept-Language'] = String(i18n.global.locale.value || 'zh-CN');
|
|
return config;
|
|
});
|
|
|
|
instance.interceptors.response.use(
|
|
(res) => {
|
|
const body = res.data;
|
|
if (body && typeof body === 'object' && 'code' in body) {
|
|
return body.code === 0 ? body.data : Promise.reject(body);
|
|
}
|
|
return body;
|
|
},
|
|
(err) => Promise.reject(err),
|
|
);
|
|
|
|
export function fetchTrace(shortCode: string): Promise<any> {
|
|
return instance.get(`/public/trace/${shortCode}`) as unknown as Promise<any>;
|
|
}
|
|
|
|
export function fetchAppInfo(): Promise<any> {
|
|
return instance.get('/settings/public') as unknown as Promise<any>;
|
|
}
|