Axios.ts 1009 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import axios from 'axios';
  2. import { MILVUS_CLIENT_ID } from '@/consts';
  3. // base hots url
  4. const DEFAULT_HOST_URL = `http://127.0.0.1:3000`;
  5. const hostUrl: { [key: string]: string | undefined } = {
  6. development: DEFAULT_HOST_URL,
  7. production: ((window as any)._env_ && (window as any)._env_.HOST_URL) || '',
  8. electron: DEFAULT_HOST_URL,
  9. };
  10. const isElectron =
  11. (window as any)._env_ && (window as any)._env_.IS_ELECTRON === 'yes';
  12. export const url = hostUrl[isElectron ? 'electron' : import.meta.env.MODE];
  13. const axiosInstance = axios.create({
  14. baseURL: `${url}/api/v1`,
  15. timeout: 60000 * 5, // 5 minutes
  16. });
  17. axiosInstance.interceptors.request.use(
  18. function (config) {
  19. // Do something before request is sent
  20. const address = window.localStorage.getItem(MILVUS_CLIENT_ID);
  21. address && (config.headers[MILVUS_CLIENT_ID] = address);
  22. return config;
  23. },
  24. function (error) {
  25. // Do something with request error
  26. return Promise.reject(error);
  27. }
  28. );
  29. export default axiosInstance;