import axios, { Method } from 'axios'; export const BASE_URL = `http://${process.env.INTERNAL_IP}:3001`; interface IFetchParams { endpoint: string; method?: Method; params?: JSON; data?: Record; } const api = async (fetchParams: IFetchParams): Promise => { const { endpoint, method = 'GET', params, data } = fetchParams; const response = await axios.request({ method, params, data, url: `${BASE_URL}${endpoint}`, withCredentials: true, }); if (response.data.error) { throw new Error(response.data.error); } if (response.data) return response.data; throw new Error(`Network request error. status : ${response.status}`); }; export default { fetch: api };