Add baseURL to axios
This commit is contained in:
parent
ee67f691d3
commit
bea9f9f5dc
|
@ -1,5 +1,7 @@
|
|||
import axios, { AxiosInstance } from 'axios';
|
||||
import { boot } from 'quasar/wrappers';
|
||||
import { StateInterface } from '../store';
|
||||
import config from '../config'
|
||||
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
|
@ -7,7 +9,17 @@ declare module 'vue/types/vue' {
|
|||
}
|
||||
}
|
||||
|
||||
export default boot(({ Vue }) => {
|
||||
export default boot(({ Vue, store }) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
Vue.prototype.$axios = axios;
|
||||
axios.defaults.baseURL = config.baseURL;
|
||||
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
const token = (<StateInterface>store.state).user.token;
|
||||
if (token) {
|
||||
config.headers['Authorization'] = 'Token ' + token.token;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
const config = {
|
||||
baseURL: "http://flaschengeist.local:5000"
|
||||
};
|
||||
|
||||
export default config;
|
Loading…
Reference in New Issue