react 프로젝트에서는 package.json 에서 "proxy" 값을 설정하여 쉽게 적용 할 수 있다.
},
"proxy":"http://localhost:8000" //접속하려는 서버의 루트 URL
}
그러면 실제 HTTP request를 전송하는 코드에서는 위에서 선언한 루트 URL을 제외한 나머지 뒷부분을 주소로 하여 요청하면 된다.
axios.get('http://localhost:8000/api/user');=>axios.get('/api/user');
-참고 블로그-
React + Express | CORS 설정하기
CORS개념은 이전 포스팅에서 다뤘으므로 생략하겠습니다. 프론트는 http://localhost:3000, 서버는 http://localhost:8000이라고 가정할 때, 프론트에서 axios.get('http://localhost:8000')하게 되면 서로 다른 o
velog.io
하지만 이방법은 로컬에서만 사용가능하다...
나는 vercel로 배포한 사이트에서 api요청을 하는데 cors에러가 발생하여 구글링을 한 결과
vercel.json으로 proxy설정 하는방법을 알게되어 적는다.
-vercel doc-
Configuring Projects with vercel.json
Learn how to use vercel.json to configure and override the default behavior of Vercel from within your project.
vercel.com
-참고한 글-
How can I setup proxy using Vercel
My API it's running under another domain.. and I'm trying to configure proxy with Vercel .. The app it's making requests to /api/test.json so I tried to... on vercel configuration "redirects&...
stackoverflow.com
// in vercel.json:
// for example proxying /api/ → https://backend-endpoint/
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "https://backend-endpoint/:path*"
},
{
"source": "/api/:path*/",
"destination": "https://backend-endpoint/:path*/"
}
]
}
'git&gitHub' 카테고리의 다른 글
GitHub 저장소에서 특정 날짜의 커밋으로 되돌리기 (0) | 2024.07.05 |
---|---|
Git - Github연결 원격 저장소(remote) 추가, 해제 (0) | 2022.10.19 |
github 협업 하기 (0) | 2022.10.14 |
Git 다운 설치 설정 (0) | 2022.08.07 |