import { AUTH_USER_ID, CLAIM_NAME } from "@/src/shared/config"; import { DEV_URL_FO, DEV_URL_WR, LOCAL_URL } from "./config/env"; import { getCookie } from "@common/components/lib/cookie"; const PROXY_HOST = process.env.NEXT_PUBLIC_PROXY_HOST || ""; const tokenId = getCookie(AUTH_USER_ID); const Authorization = getCookie(CLAIM_NAME); export const getFetch = async (part : string, url: string) => { let reqUrl = ""; reqUrl = part === "fo" ? DEV_URL_FO+url : part === 'local' ? LOCAL_URL+url : DEV_URL_WR+url; reqUrl = PROXY_HOST + reqUrl; const response = await fetch(reqUrl , { method: "GET", headers: { accept: "application/json", [AUTH_USER_ID]: tokenId ?? "", [CLAIM_NAME]: Authorization ?? "", } }); if(!response.ok) { throw new Error(`오류 발생: ${response.status}`); } const res = await response.json() return res; } export const getFetchAreaList = async (url: string) => { const response = await fetch(PROXY_HOST+url , { method: "GET", headers: { accept: "application/json", [AUTH_USER_ID]: tokenId ?? "", [CLAIM_NAME]: Authorization ?? "", } }); if(!response.ok) { throw new Error(`오류 발생: ${response.status}`); } const res = await response.json() return res; } export const postFetch = async (part : string, url: string, params: unknown) => { let reqUrl = ""; reqUrl = part === "fo" ? DEV_URL_FO+url : DEV_URL_WR+url; reqUrl = PROXY_HOST + reqUrl; const response = await fetch(reqUrl, { method: "POST", headers: { "Content-Type": "application/json", [AUTH_USER_ID]: tokenId ?? "", [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(params), }); if(!response.ok) { throw new Error(`오류 발생: ${response.status}`); } return await response.json(); } export const putFetch = async (part : string, url: string, params: unknown) => { let reqUrl = ""; reqUrl = part === "fo" ? DEV_URL_FO+url : DEV_URL_WR+url; reqUrl = PROXY_HOST + reqUrl; const response = await fetch(reqUrl, { method: "PUT", headers: { "Content-Type": "application/json", [AUTH_USER_ID]: tokenId ?? "", [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(params), }); if(!response.ok) { throw new Error(`오류 발생: ${response.status}`); } return response; } export const deleteFetch = async (part : string, url: string, params: unknown) => { let reqUrl = ""; reqUrl = part === "fo" ? DEV_URL_FO+url : DEV_URL_WR+url; reqUrl = PROXY_HOST + reqUrl; const response = await fetch(reqUrl, { method: "DELETE", headers: { "Content-Type": "application/json", [AUTH_USER_ID]: tokenId ?? "", [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(params), }); if(!response.ok) { throw new Error(`오류 발생: ${response.status}`); } return response; }