Add baseURL to axios

This commit is contained in:
Ferdinand Thiessen 2020-10-15 03:35:44 +02:00
parent ee67f691d3
commit bea9f9f5dc
2 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,7 @@
import axios, { AxiosInstance } from 'axios'; import axios, { AxiosInstance } from 'axios';
import { boot } from 'quasar/wrappers'; import { boot } from 'quasar/wrappers';
import { StateInterface } from '../store';
import config from '../config'
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface 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 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Vue.prototype.$axios = axios; 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;
});
}); });

5
src/config.ts Normal file
View File

@ -0,0 +1,5 @@
const config = {
baseURL: "http://flaschengeist.local:5000"
};
export default config;