import axios from 'axios';

const API_BASE_URL = '/api';

const request = axios.create({
  baseURL: API_BASE_URL,
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
  },
});

// 响应拦截器
request.interceptors.response.use(
  (response: any) => {
    const { data } = response;
    if (data.success) {
      return data;
    } else {
      throw new Error(data.message || '请求失败');
    }
  },
  (error: any) => {
    return Promise.reject(error);
  }
);

export { request };