http.js 760 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. import axios from "axios";
  3. let config = {
  4. baseURL: import.meta.env.VITE_APP_CYGX_BASEAPIURL,
  5. timeout: 60 * 1000, // Timeout
  6. };
  7. const _axios = axios.create(config);
  8. _axios.interceptors.request.use(
  9. function (config) {
  10. let auth = localStorage.getItem("Authorization") || "";
  11. if (auth) {
  12. config.headers.Authorization = auth;
  13. }
  14. return config;
  15. },
  16. function (error) {
  17. return Promise.reject(error);
  18. }
  19. );
  20. _axios.interceptors.response.use(
  21. function (response) {
  22. return response.data;
  23. },
  24. function (error) {
  25. return Promise.reject(error);
  26. }
  27. );
  28. export const get = (url, params) => {
  29. return _axios.get(url, { params });
  30. };
  31. export const post = (url, params) => {
  32. return _axios.post(url, params);
  33. };