You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import { AxiosInstance } from 'axios'
const baseURLMap = { package: 'http://154.88.7.8:45321/api/v1', movie: 'http://47.113.117.106:10000/api/v1', default: 'http://127.0.0.1:8686/api/v1', }
/** * 拦截url,适应不同的baseURL * @param axiosInstance */ export const requestBaseUrlInterceptors = (axiosInstance: AxiosInstance) => {
//拦截url,适应不同的baseURL
axiosInstance.interceptors.request.use((config) => { const { url } = config //取url的第1个/后的字符串
const key = url?.split('/')[1] const baseURL = baseURLMap[key!] if (baseURL) { config.baseURL = baseURL } else { config.baseURL = baseURLMap['default'] } return config }, (error) => { // console.log('error', error)
return Promise.reject(error) }) }
|