This commit is contained in:
2026-05-02 17:04:37 +02:00
parent b0509818b2
commit e12b48b3e1
2 changed files with 21 additions and 3 deletions

View File

@@ -0,0 +1,20 @@
// composables/useApi.js
import axios from 'axios';
export const useApi = () => {
const config = useRuntimeConfig();
const server = axios.create({
baseURL: config.public.apiBaseUrl,
});
server.interceptors.request.use((cfg) => {
const token = localStorage.getItem('token');
if (token) {
cfg.headers.Authorization = `Bearer ${token}`;
}
return cfg;
});
return server;
};

View File

@@ -1,9 +1,7 @@
import axios from 'axios'; import axios from 'axios';
import { backendUrl } from './BackendURL';
const server = axios.create({ const server = axios.create({
baseURL: backendUrl, baseURL: import.meta.env.API_BASE_URL || 'http://localhost:5000/api',
headers: { headers: {
"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Origin": "*",
} }