import axios from 'axios'
// import {getHeaders} from '../utils/token'

// const baseUrl = 'http://localhost:8083/api/'
// const baseUrl = 'https://api.tomey.live/api/'
const baseUrl = 'http://mytwins.top/api/'
class HttpRequest {
  constructor (baseUrl) {
    this.baseUrl = baseUrl
  }
  request (options) {
    let token = sessionStorage.getItem('token')
    let expiration = sessionStorage.getItem('expiration')
    let nowDate = new Date().getTime()
    if (nowDate - expiration > 7000000) {
      // getHeaders()
    }
    const instance = axios.create()
    options = Object.assign({
      baseURL: this.baseUrl,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
        token: token
      },
      method: 'post'
    }, options)
    return instance(options).then(res => {
      return res
    })
  }
}
const api_axios = new HttpRequest(baseUrl)
export default api_axios
