fix: axios 요청 파라미터 패턴 간단하게 수정
This commit is contained in:
parent
02635033ae
commit
d410a8cd89
@ -1,4 +1,4 @@
|
|||||||
import axios from 'axios'
|
import axios, { Axios } from 'axios'
|
||||||
|
|
||||||
export const AxiosType = {
|
export const AxiosType = {
|
||||||
INTERNAL: 'Internal',
|
INTERNAL: 'Internal',
|
||||||
@ -6,7 +6,10 @@ export const AxiosType = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useAxios() {
|
export function useAxios() {
|
||||||
const getInstances = (type) => {
|
const getInstances = (url) => {
|
||||||
|
let type = AxiosType.INTERNAL
|
||||||
|
url.startsWith('http') ? (type = AxiosType.EXTERNAL) : ''
|
||||||
|
|
||||||
return axios.create({
|
return axios.create({
|
||||||
baseURL: type === AxiosType.INTERNAL ? process.env.NEXT_PUBLIC_API_SERVER_PATH : '',
|
baseURL: type === AxiosType.INTERNAL ? process.env.NEXT_PUBLIC_API_SERVER_PATH : '',
|
||||||
headers: {
|
headers: {
|
||||||
@ -28,36 +31,36 @@ export function useAxios() {
|
|||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
const get = async ({ type, url }) => {
|
const get = async ({ url }) => {
|
||||||
return await getInstances(type)
|
return await getInstances(url)
|
||||||
.get(url)
|
.get(url)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const post = async ({ type, url, data }) => {
|
const post = async ({ url, data }) => {
|
||||||
return await getInstances(type)
|
return await getInstances(url)
|
||||||
.post(url, data)
|
.post(url, data)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const put = async ({ type, url, data }) => {
|
const put = async ({ url, data }) => {
|
||||||
return await getInstances(type)
|
return await getInstances(url)
|
||||||
.put(url, data)
|
.put(url, data)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const patch = async ({ type, url, data }) => {
|
const patch = async ({ url, data }) => {
|
||||||
return await getInstances(type)
|
return await getInstances(url)
|
||||||
.patch(url, data)
|
.patch(url, data)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const del = async ({ type, url }) => {
|
const del = async ({ url }) => {
|
||||||
return await getInstances(type)
|
return await getInstances(url)
|
||||||
.delete(url)
|
.delete(url)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user