import axios from 'axios'

const api = {
 
  
  // 定义API接口地址
  // baseURL: process.env.NODE_ENV === 'production' ? '/api/' : 'http://localhost:3000/',
  // GET请求示例
  baseURL: 'http://39.101.165.228:9001',
  baseURL2: 'http://39.101.165.228:9001',

  //永盛
  baseURL2: 'http://123.207.37.67:9001',
  baseURL22: 'http://123.207.37.67:9001',


  get (url) {
    return new Promise((resolve, reject) => {
      axios({
        method: 'get',
        url: this.baseURL + url
      })
        .then(response => resolve(response))
        .catch(error => reject(error))
    })
  },
  // POST请求示例
  post (url, data, token) {
    const headers = {}
    if (token) {
      headers['Token'] = token
    }
    return new Promise((resolve, reject) => { 
      axios({
        method: 'post',
        url: this.baseURL + url,
        data: data,
        headers: headers
      })
        .then(response => resolve(response.data))
        .catch(error => reject(error))
    })
  },
  // POST请求示例
  post2 (url, data, token) {
    const headers = {}
    if (token) {
      headers['Token'] = token
    }
    return new Promise((resolve, reject) => {
      axios({
        method: 'post',
        url: this.baseURL2 + url,
        data: data,
        headers: headers
      })
        .then(response => resolve(response.data))
        .catch(error => reject(error))
    })
  }
}

export default api
