23 lines
631 B
TypeScript
23 lines
631 B
TypeScript
import axios from 'axios';
|
|
|
|
// The base URL should typically come from an environment variable in a real app,
|
|
// but for development we can default to localhost.
|
|
export const apiClient = axios.create({
|
|
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000',
|
|
timeout: 10000,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
// Interceptor to attach token to requests if we have one
|
|
apiClient.interceptors.request.use((config) => {
|
|
const token = localStorage.getItem('token');
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
return config;
|
|
});
|
|
|
|
export default apiClient;
|