mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 21:44:51 +00:00
* refactor: add HTTP client wrapper and upgrade axios to v1 Introduce a thin HTTP wrapper (resources/scripts/http) that centralizes axios configuration, interceptors, and auth header injection. All 43 files now import from the wrapper instead of axios directly, making future library swaps a single-file change. Upgrade axios from 0.30.0 to 1.14.0. * fix: restore window.Ls assignment removed during axios refactor company.js uses window.Ls.set() to persist selected company, which broke after the axios plugin (that set window.Ls) was deleted.
41 lines
804 B
JavaScript
Vendored
41 lines
804 B
JavaScript
Vendored
import axios from 'axios'
|
|
import Ls from '@/scripts/services/ls.js'
|
|
|
|
window.Ls = Ls
|
|
|
|
const instance = axios.create({
|
|
withCredentials: true,
|
|
headers: {
|
|
common: {
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
},
|
|
},
|
|
})
|
|
|
|
instance.interceptors.request.use(function (config) {
|
|
const companyId = Ls.get('selectedCompany')
|
|
const authToken = Ls.get('auth.token')
|
|
|
|
if (authToken) {
|
|
config.headers.Authorization = authToken
|
|
}
|
|
|
|
if (companyId) {
|
|
config.headers.company = companyId
|
|
}
|
|
|
|
return config
|
|
})
|
|
|
|
function http(config) {
|
|
return instance(config)
|
|
}
|
|
|
|
http.get = instance.get.bind(instance)
|
|
http.post = instance.post.bind(instance)
|
|
http.put = instance.put.bind(instance)
|
|
http.delete = instance.delete.bind(instance)
|
|
http.patch = instance.patch.bind(instance)
|
|
|
|
export default http
|