import axios from 'axios'

const service = axios.create({
  baseURL: '', // use relative so vite proxy/public works
  timeout: 5000
})

service.interceptors.request.use(cfg => {
  const token = localStorage.getItem('token')
  if (token) cfg.headers['Authorization'] = `Bearer ${token}`
  return cfg
}, err => Promise.reject(err))

service.interceptors.response.use(res => res.data, err => Promise.reject(err))

export default service
