mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-03 09:34:51 +02:00
init
This commit is contained in:
commit
495af35043
106 changed files with 18798 additions and 0 deletions
25
plugins/axios.js
Normal file
25
plugins/axios.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
export default function ({ $axios, store }) {
|
||||
$axios.onRequest(config => {
|
||||
console.log('[Axios] Making request to ' + config.url)
|
||||
if (config.url.startsWith('http:') || config.url.startsWith('https:')) {
|
||||
return
|
||||
}
|
||||
var bearerToken = store.getters['user/getToken']
|
||||
if (bearerToken) {
|
||||
config.headers.common['Authorization'] = `Bearer ${bearerToken}`
|
||||
} else {
|
||||
console.warn('[Axios] No Bearer Token for request')
|
||||
}
|
||||
|
||||
var serverUrl = store.state.serverUrl
|
||||
if (serverUrl) {
|
||||
config.url = `${serverUrl}${config.url}`
|
||||
}
|
||||
console.log('[Axios] Request out', config.url)
|
||||
})
|
||||
|
||||
$axios.onError(error => {
|
||||
const code = parseInt(error.response && error.response.status)
|
||||
console.error('Axios error code', code)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue