import axios from 'axios'
import { setupInterceptor } from './interceptors'

const mockBaseURL = window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API_MOCK || import.meta.env.VITE_APP_GLOB_BASE_API_MOCK
const defBaseURL = window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API || import.meta.env.VITE_APP_GLOB_BASE_API
const baseURL = import.meta.env.VITE_APP_USE_MOCK === 'true' ? mockBaseURL : defBaseURL
function createAxios(option = {}) {
  const service = axios.create({
    timeout: option.timeout || 120000,
    baseURL: (option.baseURL || defBaseURL) + import.meta.env.VITE_SERVER
  })
  setupInterceptor(service)
  return service
}

export const defAxios = createAxios({ baseURL })
