-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from TripMingle/fix/SWM-272
[fix/SWM-272] 오류, middleware, apihandler, error 처리 수정
- Loading branch information
Showing
30 changed files
with
463 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
|
||
export default function Error({ | ||
error, | ||
reset, | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
console.error('Error occurred:', error); | ||
const router = useRouter(); | ||
return ( | ||
<div> | ||
<h2>잘못된 나라 입력입니다.</h2> | ||
<p>{error.message}</p> | ||
<button onClick={() => router.replace('/')}>메인 페이지로 이동하기</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
import { getAccessToken } from '@/utils/server/token'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const POST = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = `/board/comment`; | ||
const body = req.body; | ||
let token = await getAccessToken(); | ||
if (!token) | ||
return NextResponse.json( | ||
{ error: 'access token이 없거나 만료되었습니다.' }, | ||
{ status: 500 }, | ||
); | ||
export const POST = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = `/board/comment`; | ||
const body = req.body; | ||
|
||
return await fetch(`${baseurl}${pathname}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token.value}`, | ||
}, | ||
body, | ||
// @ts-ignore -- 연결이 단방향임을 나타냄 | ||
duplex: 'half', | ||
}); | ||
}; | ||
return await fetch(`${baseurl}${pathname}`, { | ||
...config, | ||
method: 'POST', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
body, | ||
// @ts-ignore -- 연결이 단방향임을 나타냄 | ||
duplex: 'half', | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import { getAccessToken } from '@/utils/server/token'; | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = '/board'; | ||
const country = req.nextUrl.searchParams.get('country'); | ||
const page = req.nextUrl.searchParams.get('page'); | ||
let accesstoken = await getAccessToken(); | ||
let token = accesstoken?.value || process.env.ACCESS_TOKEN; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = '/board'; | ||
const country = req.nextUrl.searchParams.get('country'); | ||
const page = req.nextUrl.searchParams.get('page'); | ||
|
||
console.log(`${baseurl}${pathname}/${country}?page=${page}`); | ||
|
||
return await fetch(`${baseurl}${pathname}/${country}?page=${page}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
}; | ||
return await fetch(`${baseurl}${pathname}/${country}?page=${page}`, { | ||
...config, | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { getAccessToken } from '@/utils/server/token'; | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
const country = req.nextUrl.searchParams.get('country'); | ||
let accesstoken = await getAccessToken(); | ||
let token = accesstoken?.value || process.env.ACCESS_TOKEN; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
const country = req.nextUrl.searchParams.get('country'); | ||
|
||
return await fetch(`${baseurl}${pathname}/${country}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
}; | ||
return await fetch(`${baseurl}${pathname}/${country}`, { | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
import { getAccessToken } from '@/utils/server/token'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = `/board/show`; | ||
const boardId = req.nextUrl.searchParams.get('boardId'); | ||
let accesstoken = await getAccessToken(); | ||
let token = accesstoken?.value || process.env.ACCESS_TOKEN; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = `/board/show`; | ||
const boardId = req.nextUrl.searchParams.get('boardId'); | ||
|
||
return await fetch(`${baseurl}${pathname}/${boardId}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
}; | ||
return await fetch(`${baseurl}${pathname}/${boardId}`, { | ||
...config, | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); | ||
|
||
export const POST = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = `/board`; | ||
const body = req.body; | ||
let token = await getAccessToken(); | ||
if (!token) | ||
return NextResponse.json( | ||
{ error: 'access token이 없거나 만료되었습니다.' }, | ||
{ status: 500 }, | ||
); | ||
export const POST = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = `/board`; | ||
const body = req.body; | ||
|
||
return await fetch(`${baseurl}${pathname}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token.value}`, | ||
}, | ||
body, | ||
// @ts-ignore -- 연결이 단방향임을 나타냄 | ||
duplex: 'half', | ||
}); | ||
}; | ||
return await fetch(`${baseurl}${pathname}`, { | ||
...config, | ||
method: 'POST', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
body, | ||
// @ts-ignore -- 연결이 단방향임을 나타냄 | ||
duplex: 'half', | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { getAccessToken } from '@/utils/server/token'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = `/board/schedule`; | ||
const boardId = req.nextUrl.searchParams.get('boardId'); | ||
let accesstoken = await getAccessToken(); | ||
let token = accesstoken?.value || process.env.ACCESS_TOKEN; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = `/board/schedule`; | ||
const boardId = req.nextUrl.searchParams.get('boardId'); | ||
|
||
return await fetch(`${baseurl}${pathname}/${boardId}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
}; | ||
return await fetch(`${baseurl}${pathname}/${boardId}`, { | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
|
||
return await fetch(`${baseurl}${pathname}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
return await fetch(`${baseurl}${pathname}`, { | ||
...config, | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
|
||
return await fetch(`${baseurl}${pathname}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
return await fetch(`${baseurl}${pathname}`, { | ||
...config, | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { baseurl, withApiHandler } from '@/utils/server/api'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
|
||
console.log(baseurl, pathname); | ||
|
||
return await fetch(`${baseurl}${pathname}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}; | ||
export const GET = withApiHandler( | ||
async (req: NextRequest, config: RequestInit) => { | ||
const pathname = req.nextUrl.pathname.slice(4); | ||
return await fetch(`${baseurl}${pathname}`, { | ||
...config, | ||
method: 'GET', | ||
headers: { | ||
...config.headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
false, | ||
); |
Oops, something went wrong.