import axios from 'axios'

const request = axios.create({
  baseURL: 'http://39.100.95.39:8089',
  timeout: 5000,
})

request.interceptors.request.use((config) => {
  return config
})

request.interceptors.response.use((response) => {
  return response.data
})

const http = {
  get(url: string, data?: any) {
    return new Promise((resolve, reject) => {
      request
        .get(url, {
          params: data,
        })
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },

  post(url: string, data?: any) {
    return new Promise((resolve, reject) => {
      request
        .post(url, data)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
}

export default http
