l-min-components 1.8.474 → 1.8.475
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.js +329 -326
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/utils/axiosConfig.js +16 -5
- package/src/utils/axiosConfig.js +16 -5
- package/src/utils/getAxiosInstance.js +20 -0
package/package.json
CHANGED
|
@@ -3,12 +3,23 @@ import { toast } from "react-toastify";
|
|
|
3
3
|
|
|
4
4
|
const pendingRequests = new Map();
|
|
5
5
|
|
|
6
|
+
// Determine baseURL based on hostname
|
|
7
|
+
const determineBaseURL = () => {
|
|
8
|
+
const hostname = window.location.hostname;
|
|
9
|
+
const isStaging = hostname.includes("staging");
|
|
10
|
+
const isLocalhost = hostname.includes("localhost");
|
|
11
|
+
|
|
12
|
+
const baseURL = isStaging || isLocalhost
|
|
13
|
+
? "https://dev-117782726-api.learngual.com"
|
|
14
|
+
: "https://api.learngual.com";
|
|
15
|
+
|
|
16
|
+
console.log("[l-min-components] Axios baseURL:", baseURL, { hostname, isStaging, isLocalhost });
|
|
17
|
+
|
|
18
|
+
return baseURL;
|
|
19
|
+
};
|
|
20
|
+
|
|
6
21
|
const axios = Axios.create({
|
|
7
|
-
baseURL:
|
|
8
|
-
window.location.hostname.includes("staging") ||
|
|
9
|
-
window.location.hostname.includes("localhost")
|
|
10
|
-
? "https://dev-117782726-api.learngual.com"
|
|
11
|
-
: "https://api.learngual.com",
|
|
22
|
+
baseURL: determineBaseURL(),
|
|
12
23
|
});
|
|
13
24
|
|
|
14
25
|
axios.interceptors.request.use(
|
package/src/utils/axiosConfig.js
CHANGED
|
@@ -3,12 +3,23 @@ import { toast } from "react-toastify";
|
|
|
3
3
|
|
|
4
4
|
const pendingRequests = new Map();
|
|
5
5
|
|
|
6
|
+
// Determine baseURL based on hostname
|
|
7
|
+
const determineBaseURL = () => {
|
|
8
|
+
const hostname = window.location.hostname;
|
|
9
|
+
const isStaging = hostname.includes("staging");
|
|
10
|
+
const isLocalhost = hostname.includes("localhost");
|
|
11
|
+
|
|
12
|
+
const baseURL = isStaging || isLocalhost
|
|
13
|
+
? "https://dev-117782726-api.learngual.com"
|
|
14
|
+
: "https://api.learngual.com";
|
|
15
|
+
|
|
16
|
+
console.log("[l-min-components] Axios baseURL:", baseURL, { hostname, isStaging, isLocalhost });
|
|
17
|
+
|
|
18
|
+
return baseURL;
|
|
19
|
+
};
|
|
20
|
+
|
|
6
21
|
const axios = Axios.create({
|
|
7
|
-
baseURL:
|
|
8
|
-
window.location.hostname.includes("staging") ||
|
|
9
|
-
window.location.hostname.includes("localhost")
|
|
10
|
-
? "https://dev-117782726-api.learngual.com"
|
|
11
|
-
: "https://api.learngual.com",
|
|
22
|
+
baseURL: determineBaseURL(),
|
|
12
23
|
});
|
|
13
24
|
|
|
14
25
|
axios.interceptors.request.use(
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the configured axios instance from axios-hooks
|
|
3
|
+
* This ensures components use the axios instance configured by the consuming app
|
|
4
|
+
*/
|
|
5
|
+
let configuredAxios = null;
|
|
6
|
+
|
|
7
|
+
export const setAxiosInstance = (axiosInstance) => {
|
|
8
|
+
configuredAxios = axiosInstance;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getAxiosInstance = () => {
|
|
12
|
+
if (!configuredAxios) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Axios instance not configured. Make sure to call configure({ axios }) from axios-hooks in your app's main.jsx"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return configuredAxios;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default getAxiosInstance;
|