From c7491f9af56a0cafc20ba9541b916c1e791d450e Mon Sep 17 00:00:00 2001 From: eddy Date: Wed, 8 Apr 2026 12:06:35 +0200 Subject: [PATCH] =?UTF-8?q?axios=20f=C3=BCr=20docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/axiosInstance.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/api/axiosInstance.js b/src/api/axiosInstance.js index 0cf86e5..9ffccb7 100644 --- a/src/api/axiosInstance.js +++ b/src/api/axiosInstance.js @@ -1,29 +1,27 @@ import axios from 'axios'; const axiosInstance = axios.create({ - baseURL: 'http://localhost:8080', // <-- dein Spring Boot Backend - headers: { 'Content-Type': 'application/json' }, + baseURL: import.meta.env.VITE_API_URL, + headers: { 'Content-Type': 'application/json' }, }); -// JWT automatisch in jeden Request hängen axiosInstance.interceptors.request.use((config) => { - const token = localStorage.getItem('jwt_token'); - if (token) { - config.headers.Authorization = `Bearer ${token}`; - } - return config; + const token = localStorage.getItem('jwt_token'); + if (token) { + config.headers.Authorization = `Bearer ${token}`; + } + return config; }); -// Bei 401 automatisch ausloggen axiosInstance.interceptors.response.use( - (response) => response, - (error) => { - if (error.response?.status === 401) { - localStorage.removeItem('jwt_token'); - window.location.href = '/login'; + (response) => response, + (error) => { + if (error.response?.status === 401) { + localStorage.removeItem('jwt_token'); + window.location.href = '/login'; + } + return Promise.reject(error); } - return Promise.reject(error); - } ); -export default axiosInstance; +export default axiosInstance; \ No newline at end of file