diff --git a/ui/src/services/api.js b/ui/src/services/api.js index c3726a8..4a5ad40 100644 --- a/ui/src/services/api.js +++ b/ui/src/services/api.js @@ -3,7 +3,9 @@ import axios from 'axios' import qs from 'qs' import { useAuthStore } from 'stores/authStore' -export const API_BASE_URL = process.env.VITE_API_BASE_URL || '/api' +// ✅ Vite uyumlu env okuma +export const API_BASE_URL = + import.meta.env.VITE_API_BASE_URL || '/api' const api = axios.create({ baseURL: API_BASE_URL, @@ -13,7 +15,9 @@ const api = axios.create({ withCredentials: true }) -// REQUEST +/* ============================ + REQUEST INTERCEPTOR +============================ */ api.interceptors.request.use((config) => { const auth = useAuthStore() const url = config.url || '' @@ -32,7 +36,9 @@ api.interceptors.request.use((config) => { return config }) -// RESPONSE +/* ============================ + RESPONSE INTERCEPTOR +============================ */ let isLoggingOut = false api.interceptors.response.use( @@ -46,10 +52,15 @@ api.interceptors.response.use( isLoggingOut = false } } + return Promise.reject(error) } ) +/* ============================ + HELPERS +============================ */ + export const get = (u, p = {}, c = {}) => api.get(u, { params: p, ...c }).then(r => r.data) @@ -63,6 +74,10 @@ export const del = (u, p = {}, c = {}) => api.delete(u, { params: p, ...c }).then(r => r.data) export const download = (u, p = {}, c = {}) => - api.get(u, { params: p, responseType: 'blob', ...c }).then(r => r.data) + api.get(u, { + params: p, + responseType: 'blob', + ...c + }).then(r => r.data) export default api