Rewrites로 api proxy 설정하기
Rewrites는 들어오는 요청 경로를 다른 대상 경로에 매핑하는 프록시 역할을 한다.
로컬 서버에서 api 요청 시 CORS 오류가 나서 rewrites 속성을 설정하였다.
1
2
3
4
5
6
7
8
9
10
11
// next.config.js
module.exports = {
async rewrites() {
return [
{
source: "/old-about/:path*",
destination: "/about", // The :path parameter isn't used here so will be automatically passed in the query
},
];
},
};
source
에 로컬 요청 경로를, destination
에 실제 요청 경로를 입력한다.
This post is licensed under CC BY 4.0 by the author.