Files
frontend/src/api/axios.ts

27 lines
786 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import axios from "axios";
const apiClient = axios.create({
// Vite предоставляет переменную import.meta.env.VITE_API_URL
// В режиме разработки это будет прокси, в продакшене - реальный URL
baseURL: import.meta.env.VITE_API_URL || "/api",
headers: {
"Content-Type": "application/json",
},
});
// Мы можем добавить interceptor для автоматического добавления JWT
apiClient.interceptors.request.use(
(config) => {
const token = localStorage.getItem("authToken");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
},
);
export default apiClient;