Download frontend/app/managers/HTTPManager.ts from Kaadan/subul: direct link, hf CLI and curl.
- Browser
- Download file 990 Bytes
-
https://huggingface.co/spaces/Kaadan/subul/resolve/main/frontend/app/managers/HTTPManager.ts
- Command line
-
hf download hf://spaces/Kaadan/subul/frontend/app/managers/HTTPManager.ts
-
curl -L -o HTTPManager.ts https://huggingface.co/spaces/Kaadan/subul/resolve/main/frontend/app/managers/HTTPManager.ts
990 Bytes
| import axios from "axios"; | |
| import { toast } from "react-toastify"; | |
| // Use runtime configuration with fallback to environment variable | |
| // Handle SSR by checking if window is available | |
| const getBaseURL = () => { | |
| if (typeof window !== 'undefined' && (window as any).APP_CONFIG?.API_BASE_URL) { | |
| return (window as any).APP_CONFIG.API_BASE_URL; | |
| } | |
| // Fallback to environment variable during build time | |
| return import.meta.env.VITE_APP_API_URL || undefined; | |
| }; | |
| const baseURL = getBaseURL(); | |
| export const HTTPManager = axios.create({ | |
| baseURL: baseURL, | |
| headers: { | |
| "Content-Type": "application/json", | |
| "Accept": "application/json", | |
| }, | |
| }); | |
| HTTPManager.interceptors.request.use((config) => { | |
| const token = localStorage.getItem("token"); | |
| if (token) { | |
| config.headers["Authorization"] = `Bearer ${token}`; | |
| } | |
| return config; | |
| }, (error) => { | |
| toast.error("Request error: " + error.message); | |
| return Promise.reject(error); | |
| }); |