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.

31 lines
802 B

3 months ago
  1. import { AxiosInstance } from 'axios'
  2. const baseURLMap = {
  3. package: 'http://154.88.7.8:45321/api/v1',
  4. movie: 'http://47.113.117.106:10000/api/v1',
  5. default: 'http://127.0.0.1:8686/api/v1',
  6. }
  7. /**
  8. * urlbaseURL
  9. * @param axiosInstance
  10. */
  11. export const requestBaseUrlInterceptors = (axiosInstance: AxiosInstance) => {
  12. //拦截url,适应不同的baseURL
  13. axiosInstance.interceptors.request.use((config) => {
  14. const { url } = config
  15. //取url的第1个/后的字符串
  16. const key = url?.split('/')[1]
  17. const baseURL = baseURLMap[key!]
  18. if (baseURL) {
  19. config.baseURL = baseURL
  20. } else {
  21. config.baseURL = baseURLMap['default']
  22. }
  23. return config
  24. }, (error) => {
  25. // console.log('error', error)
  26. return Promise.reject(error)
  27. })
  28. }