si
This commit is contained in:
20
frontend/app/composables/useApi.ts
Normal file
20
frontend/app/composables/useApi.ts
Normal 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;
|
||||
};
|
||||
@@ -1,9 +1,7 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import { backendUrl } from './BackendURL';
|
||||
|
||||
const server = axios.create({
|
||||
baseURL: backendUrl,
|
||||
baseURL: import.meta.env.API_BASE_URL || 'http://localhost:5000/api',
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user