Files
znakovni.hr/packages/frontend/src/lib/api.ts
johnny2211 030491fc5a Fix Docker deployment: Replace hardcoded localhost:3000 with environment-aware URLs
- Fixed API client to respect empty VITE_API_URL for same-origin requests
- Fixed video URL construction in videoPlaylist.ts
- Fixed video URL construction in VideoUpload.tsx
- All three files now use explicit undefined check instead of || operator
- Enables proper same-origin requests via nginx proxy in Docker

Co-Authored-By: Auggie
2026-01-18 17:26:44 +01:00

27 lines
596 B
TypeScript

import axios from 'axios';
const API_URL = import.meta.env.VITE_API_URL !== undefined ? import.meta.env.VITE_API_URL : 'http://localhost:3000';
export const api = axios.create({
baseURL: API_URL,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
},
});
// Response interceptor for error handling
api.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
// Redirect to login on unauthorized
window.location.href = '/login';
}
return Promise.reject(error);
}
);
export default api;