first rest request
This commit is contained in:
32
web/themes/custom/caravane/assets/js/api/json-axios.js
Normal file
32
web/themes/custom/caravane/assets/js/api/json-axios.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import axios from 'axios'
|
||||
|
||||
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
|
||||
|
||||
// console.log('drupalSettings', drupalSettings)
|
||||
console.log(window.location)
|
||||
|
||||
const JSONAPI = axios.create({
|
||||
baseURL: `${window.location.origin}/jsonapi`,
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
Accept: 'application/vnd.api+json'
|
||||
// Authorization: 'Basic {token}',
|
||||
// 'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
JSONAPI.interceptors.response.use(
|
||||
response => {
|
||||
return Promise.resolve(response)
|
||||
},
|
||||
error => {
|
||||
const { status } = error.response
|
||||
console.warn('error in json-axios', status)
|
||||
// if (status === 403) {
|
||||
// window.location = '/'
|
||||
// }
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default JSONAPI
|
45
web/themes/custom/caravane/assets/js/api/rest-axios.js
Normal file
45
web/themes/custom/caravane/assets/js/api/rest-axios.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import axios from 'axios'
|
||||
|
||||
// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js
|
||||
|
||||
// console.log('drupalSettings', drupalSettings)
|
||||
// console.log('window.location.origin', window.location.origin)
|
||||
|
||||
// axios.interceptors.response.use(
|
||||
// response => {
|
||||
// return Promise.resolve(response)
|
||||
// },
|
||||
// error => {
|
||||
// const { status } = error.response
|
||||
// console.warn('error in rest-axios', status)
|
||||
// if (status === 403) {
|
||||
// window.location = '/'
|
||||
// }
|
||||
// return Promise.reject(error)
|
||||
// }
|
||||
// )
|
||||
|
||||
const REST = axios.create({
|
||||
baseURL: `${window.location.origin}`,
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
// Authorization: 'Bearer {token}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
REST.interceptors.response.use(
|
||||
response => {
|
||||
return Promise.resolve(response)
|
||||
},
|
||||
error => {
|
||||
const { status } = error.response
|
||||
console.warn('error in rest-axios', status)
|
||||
// if (status === 403) {
|
||||
// window.location = '/'
|
||||
// }
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default REST
|
Reference in New Issue
Block a user