//8880 import { AUTH_USER_ID, CLAIM_NAME } from "@/src/shared/config"; import { DEV_URL_FO, DEV_URL_WR } from "../config"; import { getCookie } from "@common/components/lib/cookie"; const tokenId = getCookie(AUTH_USER_ID); const Authorization = getCookie(CLAIM_NAME); export const fetchType = { COMMON: "common", WR: "wr", FO:'fo' }; interface RequestParams { [key: string]: unknown; } export const getFetch = async (type: string, url: string) => { const baseUrl = type === fetchType.FO ? DEV_URL_FO : DEV_URL_WR; const response = await fetch(baseUrl + 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 (url: string, params: RequestParams) => { const response = await fetch(DEV_URL_WR + url, { 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 response; }; export const putFetch = async (url: string, params: RequestParams) => { const response = await fetch(DEV_URL_WR + url, { 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 (url: string, params: RequestParams) => { const response = await fetch(DEV_URL_WR + url, { 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; };