mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-21 22:18:03 +02:00
- Remove separate backend/ and frontend/ Dockerfiles - Add root Dockerfile (3-stage: frontend build → backend build → runtime) - Frontend static files served by Express from /public - Simplify docker-compose to 3 services: mongodb, redis, app (port 3579) - Fix vite proxy not to strip /api prefix from paths - Default API URL to relative /api instead of hardcoded localhost Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
36 lines
833 B
TypeScript
36 lines
833 B
TypeScript
import axios from 'axios';
|
|
|
|
const API_URL = import.meta.env.VITE_API_URL || '/api';
|
|
|
|
const api = axios.create({
|
|
baseURL: API_URL,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
// Add auth token to requests
|
|
api.interceptors.request.use((config) => {
|
|
const token = localStorage.getItem('accessToken');
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
return config;
|
|
});
|
|
|
|
// Handle token refresh on 401
|
|
api.interceptors.response.use(
|
|
(response) => response,
|
|
async (error) => {
|
|
if (error.response?.status === 401) {
|
|
// Token expired - could implement refresh token logic here
|
|
localStorage.removeItem('accessToken');
|
|
localStorage.removeItem('refreshToken');
|
|
window.location.href = '/login';
|
|
}
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default api;
|