Frontend v.0.1

This commit is contained in:
2026-02-12 17:29:24 +01:00 Verified
parent f8fe3eb991
commit c12d962da0
20 changed files with 2087 additions and 181 deletions
+42
View File
@@ -0,0 +1,42 @@
// frontend/src/services/api.js
import axios from 'axios';
const getBackendHost = () => {
const host = window.location.hostname || 'localhost';
return host;
};
// Updated to include /api prefix
export const API_BASE = `${window.location.protocol}//${getBackendHost()}:8000/api`;
export const WS_URL = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${getBackendHost()}:8000/ws`;
const api = axios.create({
baseURL: API_BASE,
headers: {
'Content-Type': 'application/json',
},
});
// Request Interceptor for Auth
api.interceptors.request.use((config) => {
const token = localStorage.getItem('volleyToken');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
// Response Interceptor for Errors
api.interceptors.response.use(
(response) => response.data,
(error) => {
if (error.response?.status === 401) {
localStorage.removeItem('volleyToken');
window.location.href = '/login';
}
return Promise.reject(error.response?.data || error.message);
}
);
export default api;