This commit is contained in:
ditiqi 2025-02-24 09:49:10 +08:00
parent 82048a115e
commit 8652488bad
1 changed files with 13 additions and 13 deletions

View File

@ -1,20 +1,20 @@
import axios from 'axios';
import { env } from '../env';
const BASE_URL = `http://${env.SERVER_IP}:3000`
import axios from "axios";
import { env } from "../env";
const BASE_URL = `http://${env.SERVER_IP}:${env.SERVER_PORT}`;
const apiClient = axios.create({
baseURL: BASE_URL,
// withCredentials: true,
baseURL: BASE_URL,
// withCredentials: true,
});
// Add a request interceptor to attach the access token
apiClient.interceptors.request.use(
(config) => {
const accessToken = localStorage.getItem('access_token');
if (accessToken) {
config.headers['Authorization'] = `Bearer ${accessToken}`;
}
return config;
},
(error) => Promise.reject(error)
(config) => {
const accessToken = localStorage.getItem("access_token");
if (accessToken) {
config.headers["Authorization"] = `Bearer ${accessToken}`;
}
return config;
},
(error) => Promise.reject(error)
);
export default apiClient;