import axios from 'axios'
// let curWwwPath = window.document.location.href
// let pathname = window.document.location.pathname
// let pos = curWwwPath.indexOf(pathname)
// let localhostPath = curWwwPath.substring(0, pos)
// let root = localhostPath + pathname
const root = 'http://localhost:8097/'
function _sendRequest (url, method, data, callback, responsetype) {
axios({
method: method,
url: url,
data: method === 'POST' || method === 'post' || method === 'PUT' || method === 'put' ? data : null,
params: method === 'GET' || method === 'get' || method === 'DELETE' || method === 'delete' ? data : null,
baseURL: root }).then(function (response) {
console.log(response)
callback(response.data)
}).catch(function (error) {
if (error.response) {
console.log('Error' + error.response.data)
console.log('Error' + error.response.status)
console.log(error.response.headers)
} else {
console.log('Error', error.message)
}
console.log(error.config)
})
}
export default {
sendRequest: function (url, method, data, callback, responseType) {
_sendRequest(url, method, data, callback, responseType)
}
}