import axios from 'axios';

import { backendUrl } from './BackendURL';

const server = axios.create({
    baseURL: backendUrl,
    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;