training_data/apps/web/src/utils/axios-client.ts

21 lines
543 B
TypeScript
Raw Normal View History

2024-09-09 18:48:07 +08:00
import axios from 'axios';
import { env } from '../env';
2025-02-24 11:50:56 +08:00
const BASE_URL = `http://${env.SERVER_IP}:${env?.SERVER_PORT}`
2024-09-09 18:48:07 +08:00
const apiClient = axios.create({
2025-02-24 09:49:10 +08:00
baseURL: BASE_URL,
// withCredentials: true,
2024-09-09 18:48:07 +08:00
});
// Add a request interceptor to attach the access token
apiClient.interceptors.request.use(
2025-02-24 09:49:10 +08:00
(config) => {
const accessToken = localStorage.getItem("access_token");
if (accessToken) {
config.headers["Authorization"] = `Bearer ${accessToken}`;
}
return config;
},
(error) => Promise.reject(error)
2024-09-09 18:48:07 +08:00
);
export default apiClient;