const BASE_URL = 'http://con.mind-one.co.kr:11083/sewerage-service/api'; export const postData = async (url: string, data: object): Promise => { const options: RequestInit = { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }; const res = await fetch(`${BASE_URL}/${url}`, options); console.log('res', res); console.log('res.status', res.status); if (res.ok) { const resData = await res.json(); return resData; // const text = await res.text(); // if (text) { // return JSON.parse(text); // JSON 데이터가 있으면 파싱하여 반환 // } // return true; // 응답 본문이 비어 있으면 true 반환 } }; export const postMutiPart = async (url: string, data: FormData): Promise => { const options: RequestInit = { method: "POST", body: data, }; const res = await fetch(`${BASE_URL}/${url}`, options); const resData = await res.json(); return resData; }; export const putData = async (url: string, data: object): Promise => { const options: RequestInit = { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }; const res = await fetch(`${BASE_URL}/${url}`, options); const resData = await res.json(); return resData; }; export const getData = async (url: string, data?: object): Promise => { const res = await fetch(url.startsWith('/') ? `${url}` : `${BASE_URL}/${url}`, { method: "GET", }); if (res.ok) { const data = await res.json(); return data; } throw new Error('Failed to fetch data'); }; export const getDcData = async (url: string, data?: object): Promise => { console.log(url); const res = await fetch('/dc-service'+url, { method: "GET", }); if (res.ok) { const data = await res.json(); return data; } throw new Error('Failed to fetch data'); }; export const deleteData = async (url: string, data?: object): Promise => { const options: RequestInit = { method: "DELETE", headers: { "Content-Type": "application/json", }, body: data ? JSON.stringify(data) : undefined, }; const res = await fetch(url.startsWith('/') ? `${url}` : `${BASE_URL}/${url}`, options); if (res.status === 204) return true return res; };