Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

서버 주소 노출 방지 및 error handler 추가 #125

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ const nextConfig = {
images: {
domains: [process.env.NEXT_PUBLIC_IMAGE_DOMAIN],
},
async rewrites() {
return [
{
source: '/server/:path*',
destination: `${process.env.NEXT_PUBLIC_SERVER_URL}/:path*`,
},
]
},
}
module.exports = nextConfig
42 changes: 17 additions & 25 deletions src/utils/apis/data.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,57 @@
import { toast } from 'react-toastify'
import { apiClient } from 'utils/libs/apiClient'
import toastOption from 'utils/libs/toastOption'
import handleError from './handleError'

export const getData = async (url: string | undefined, params?: any) => {
try {
let config = {
params: params,
}
const config = { params }
const { data } = await apiClient.get(url || '', config)
return { data }
} catch (e: any) {
toast.error(e.response.data.message, toastOption)
throw e
} catch (e) {
handleError(e)
}
}

export const postData = async (url: string, body?: any) => {
try {
const { data } = await apiClient.post(url || '', body)
} catch (e: any) {
throw e
return { data }
} catch (e) {
handleError(e)
}
}

export const postFormData = async (url: string, data: any) => {
try {
await apiClient.post(url || '', data, {
headers: {
'Content-Type': 'multipart/form-data',
},
headers: { 'Content-Type': 'multipart/form-data' },
})
} catch (e: any) {
throw e
} catch (e) {
handleError(e)
}
}

export const patchFormData = async (url: string, data: any) => {
try {
await apiClient.patch(url || '', data, {
headers: {
'Content-Type': 'multipart/form-data',
},
headers: { 'Content-Type': 'multipart/form-data' },
})
} catch (e: any) {
throw e
} catch (e) {
handleError(e)
}
}

export const patchData = async (url: string, data?: any) => {
try {
await apiClient.patch(url || '', data)
} catch (e: any) {
throw e
} catch (e) {
handleError(e)
}
}

export const deleteData = async (url: string, params?: any) => {
try {
await apiClient.delete(url || '', { params })
} catch (e: any) {
toast.error(e.response.data.message, toastOption)
throw e
} catch (e) {
handleError(e)
}
}
11 changes: 11 additions & 0 deletions src/utils/apis/handleError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { toast } from 'react-toastify'
import toastOption from 'utils/libs/toastOption'

const handleError = (error: any) => {
const errorMessage =
error.response?.data?.message || '알 수 없는 에러가 발생했습니다.'
toast.error(errorMessage, toastOption)
throw error
}

export default handleError
2 changes: 1 addition & 1 deletion src/utils/libs/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getRefresh } from './getRefresh'
import BASE_HEADER from '../Config/Config.json'

export const apiClient = axios.create({
baseURL: process.env.NEXT_PUBLIC_SERVER_URL,
baseURL: '/server',
withCredentials: true,
headers: BASE_HEADER,
})
Expand Down