Spaces:
Running
Running
File size: 620 Bytes
2ecc4a7 73905db 2ecc4a7 73905db 2ecc4a7 73905db 2ecc4a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import axios from 'axios';
const getApiBaseUrl = () => {
if (import.meta.env.VITE_API_BASE_URL) return import.meta.env.VITE_API_BASE_URL;
if (typeof window !== 'undefined' && (window.location.port === '5173' || window.location.port === '5174')) {
return 'http://127.0.0.1:8008';
}
return window.location.origin;
};
const api = axios.create({
baseURL: getApiBaseUrl(),
});
// Interceptor for JWT
api.interceptors.request.use((config) => {
const token = sessionStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
export default api;
|