mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-06-03 08:58:59 +00:00
Add HTTP client wrapper and upgrade Axios to v1 (#594)
* 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.
This commit is contained in:
committed by
GitHub
parent
a38f09cf7b
commit
691178857f
31
resources/scripts/plugins/axios.js
vendored
31
resources/scripts/plugins/axios.js
vendored
@@ -1,31 +0,0 @@
|
||||
import axios from 'axios'
|
||||
import Ls from '@/scripts/services/ls.js'
|
||||
|
||||
window.Ls = Ls
|
||||
window.axios = axios
|
||||
axios.defaults.withCredentials = true
|
||||
|
||||
axios.defaults.headers.common = {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
}
|
||||
|
||||
/**
|
||||
* Interceptors
|
||||
*/
|
||||
|
||||
axios.interceptors.request.use(function (config) {
|
||||
// Pass selected company to header on all requests
|
||||
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
|
||||
})
|
||||
Reference in New Issue
Block a user