File size: 713 Bytes
b1cc7ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import axios, {AxiosResponse} from "axios";
import {useCache} from "@/hooks/useCache";
import {toggleError} from '@/hooks/showError'
import router from "@/router";

const { wsCache } = useCache();

export const test_server = '127.0.0.1:9191'
// export const test_server = '59.110.18.232:19001'

axios.defaults.baseURL = import.meta.env.PROD  ?  '/api' : `http://${test_server}/api`;
axios.interceptors.request.use(
    (config: any) => {
        // Do something before request is sent
        const {wsCache} = useCache()
        const token = wsCache.get('token')
        if (token) {
            //@ts-ignore
            config.headers.Authorization = 'Bearer ' + token
        }
        return config;
    }
)