31 lines
743 B
TypeScript
31 lines
743 B
TypeScript
|
|
import axios from 'axios';
|
||
|
|
|
||
|
|
// Create an Axios instance
|
||
|
|
const api = axios.create({
|
||
|
|
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3000/api',
|
||
|
|
withCredentials: true, // Send cookies with requests if needed
|
||
|
|
});
|
||
|
|
|
||
|
|
api.interceptors.request.use(
|
||
|
|
(config) => {
|
||
|
|
// Example: Add lang cookie from browser (client-side only)
|
||
|
|
if (typeof window !== 'undefined') {
|
||
|
|
const match = document.cookie.match(/(^| )lang=([^;]+)/);
|
||
|
|
if (match) {
|
||
|
|
config.headers['lang'] = decodeURIComponent(match[2]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return config;
|
||
|
|
},
|
||
|
|
(error) => Promise.reject(error),
|
||
|
|
);
|
||
|
|
|
||
|
|
api.interceptors.response.use(
|
||
|
|
(response) => response,
|
||
|
|
(error) => {
|
||
|
|
return Promise.reject(error);
|
||
|
|
},
|
||
|
|
);
|
||
|
|
|
||
|
|
export default api;
|