import { useTokenStore } from '@/store'
import axios, { AxiosResponse } from 'axios'


const baseURL = process.env.NODE_ENV === 'development' ? '/api' : '/zd-api'

// 'https://open.api.luojigou.vip/'

const instance = axios.create({
  baseURL: baseURL,
  timeout: 1000
})

instance.interceptors.request.use((config) => {

  config.headers['token'] = useTokenStore().get()

  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})

instance.interceptors.response.use(<T>(response: AxiosResponse<T>) => {
  return response.data
}, (error) => {
  return Promise.reject(error)
})

export default instance
