All checks were successful
Build and Deploy Nuxt / build (push) Successful in 41s
19 lines
502 B
JavaScript
19 lines
502 B
JavaScript
import axios from 'axios';
|
|
|
|
const server = axios.create({
|
|
baseURL: import.meta.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:5000/api',
|
|
headers: {
|
|
"Access-Control-Allow-Origin": "*",
|
|
}
|
|
});
|
|
|
|
// Attach token dynamically on each request via interceptor
|
|
server.interceptors.request.use((config) => {
|
|
const token = localStorage.getItem('token');
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
return config;
|
|
});
|
|
|
|
export default () => server; |