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 = {
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user