mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 17:28:28 +00:00
27 lines
639 B
TypeScript
27 lines
639 B
TypeScript
import axios from "axios";
|
|
|
|
// Create a custom Axios instance
|
|
const axiosInstance = axios.create({
|
|
baseURL: process.env.API_BASE_URL,
|
|
timeout: 10000, // 10 seconds timeout
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
|
|
// Add a request interceptor to inject the Authorization header
|
|
axiosInstance.interceptors.request.use(
|
|
(config) => {
|
|
// Add Authorization header if API_TOKEN is available
|
|
if (process.env.API_TOKEN) {
|
|
config.headers.Authorization = `Bearer ${process.env.API_TOKEN}`;
|
|
}
|
|
return config;
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default axiosInstance;
|