From d410a8cd890aa4fce0749b09f61d5a16648d977a Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Mon, 12 Aug 2024 15:10:35 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20axios=20=EC=9A=94=EC=B2=AD=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=20=ED=8C=A8=ED=84=B4=20=EA=B0=84?= =?UTF-8?q?=EB=8B=A8=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useAxios.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/hooks/useAxios.js b/src/hooks/useAxios.js index 9e188ba7..04f1f304 100644 --- a/src/hooks/useAxios.js +++ b/src/hooks/useAxios.js @@ -1,4 +1,4 @@ -import axios from 'axios' +import axios, { Axios } from 'axios' export const AxiosType = { INTERNAL: 'Internal', @@ -6,7 +6,10 @@ export const AxiosType = { } export function useAxios() { - const getInstances = (type) => { + const getInstances = (url) => { + let type = AxiosType.INTERNAL + url.startsWith('http') ? (type = AxiosType.EXTERNAL) : '' + return axios.create({ baseURL: type === AxiosType.INTERNAL ? process.env.NEXT_PUBLIC_API_SERVER_PATH : '', headers: { @@ -28,36 +31,36 @@ export function useAxios() { // } }) - const get = async ({ type, url }) => { - return await getInstances(type) + const get = async ({ url }) => { + return await getInstances(url) .get(url) .then((res) => res.data) .catch(console.error) } - const post = async ({ type, url, data }) => { - return await getInstances(type) + const post = async ({ url, data }) => { + return await getInstances(url) .post(url, data) .then((res) => res.data) .catch(console.error) } - const put = async ({ type, url, data }) => { - return await getInstances(type) + const put = async ({ url, data }) => { + return await getInstances(url) .put(url, data) .then((res) => res.data) .catch(console.error) } - const patch = async ({ type, url, data }) => { - return await getInstances(type) + const patch = async ({ url, data }) => { + return await getInstances(url) .patch(url, data) .then((res) => res.data) .catch(console.error) } - const del = async ({ type, url }) => { - return await getInstances(type) + const del = async ({ url }) => { + return await getInstances(url) .delete(url) .then((res) => res.data) .catch(console.error)