Spaces:
Running
Running
Bibhu Mishra
Add GitHub Actions CI/CD, HF Space deployment, market hours guard, and static serving
abc493d | import axios from 'axios' | |
| const api = axios.create({ | |
| baseURL: import.meta.env.VITE_API_URL ?? 'http://localhost:3000/api', | |
| }) | |
| api.interceptors.request.use((config) => { | |
| const token = localStorage.getItem('token') | |
| if (token) config.headers.Authorization = `Bearer ${token}` | |
| return config | |
| }) | |
| api.interceptors.response.use( | |
| (r) => r, | |
| (err) => { | |
| const url: string = err.config?.url ?? '' | |
| const isAuthCall = url.includes('/auth/') | |
| if (err.response?.status === 401 && !isAuthCall) { | |
| localStorage.removeItem('token') | |
| if (window.location.pathname !== '/login') { | |
| window.location.href = '/login' | |
| } | |
| } | |
| return Promise.reject(err) | |
| }, | |
| ) | |
| export default api | |