feat(frontend): initialize Vue 3 + Vite project structure
This commit is contained in:
26
src/api/axios.ts
Normal file
26
src/api/axios.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user