import axios from 'axios'

const baseURL = import.meta.env.VITE_API_BASE_URL || (import.meta.env.PROD ? '/api/api' : '/api')

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

instance.interceptors.response.use(
  (res) => res,
  (err) => {
    const message = err.response?.data?.message ?? err.message ?? '请求失败'
    console.error('[API Error]', message)
    return Promise.reject(err)
  }
)

export default instance
