외부 api 연동 cross origin 에러
2073
작성한 질문수 1
안녕하세요.
강의 내용을 활용해서 외부 api를 연동해서 연습중인데
dev 환경이라 그런지 cross origin 에러로 호출을 못하고 있습니다.
어떻게 해결을 해야할까요?
에러 로그------------------------------------------------------------------------------------------------------------
origin 'http://localhost:3060' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
답변 7
3
서버쪽을 건들 수 없는 상황이면 proxy 서버를 띄우는 것밖에 답이 없습니다. 저 위에 에러는 CORS는 적용되었는데 쿠키까지 사용하려면 CORS 설정을 조금 바꿔줘야한다는 거라서 서버쪽에서 수정을 해야하는 문제입니다. proxy 서버는
https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewriting-to-an-external-url
이렇게 설정할 수 있습니다. 또는 http-proxy-middleware를 쓰거나요.
2
module.exports를 두 번 쓰신건가요? 한 파일에서 한 번만 쓸 수 있습니다. async rewrites를 compress 위에 넣으시면 될듯 합니다.
1
머가 다른 셋팅을 추가적으로 해줘야하나요? 여러 방법으로 시도중인데 안되서 주석처리하고 따로 빼줘도 안되네요 미들웨어 추가도 안되고 죄송하지만 한번더 문의드립니다.ㅜㅜ
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
/*
module.exports = withBundleAnalyzer({
compress: true,
webpack(config, { webpack }) {
const prod = process.env.NODE_ENV === 'production';
return {
...config,
mode: prod ? 'production' : 'development',
devtool: prod ? 'hidden-source-map' : 'eval',
plugins: [
...config.plugins,
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /^\.\/ko$/),
],
};
},
});*/
module.exports = {
async rewrites() {
return [
// we need to define a no-op rewrite to trigger checking
// all pages/static files before we attempt proxying
{
source: '/:path*',
destination: '/:path*',
},
{
source: '/:path*',
destination: `http://api-stage.test.com:1313/:path*`,
},
]
},
}
0
api 서버에 localhost 등록이 된상태입니다. 2년전에 배운 react redux-thunk 베이스(프록시 서버X)에서 테스트 시 이상이 없었습니다. 이런 상황이면 어떤 부분을 의심해봐야할까요? 기초가 부족해서 그런지 찾아볼려고해도 감이 안잡혀서 난감한 상황입니다ㅜㅜ
넥스트 버젼 질문
0
77
2
로그인시 401 Unauthorized 오류가 뜹니다
0
89
1
무한 스크롤 중 스크롤 튐 현상
0
174
1
특정 페이지 접근을 막고 싶을 때
0
103
2
createGlobalStyle의 위치와 영향범위
0
96
2
인라인 스타일 리렌더링 관련
0
91
2
vsc 에서 npm init 설치시 오류
0
146
2
nextjs 15버전 사용 가능할까요?
0
158
1
화면 새로고침 문의
0
121
1
RTK에서 draft, state 차이가 있나요?
0
153
2
Next 14 사용해도 될까요?
0
452
1
next, node 버전 / 폴더 구조 질문 드립니다.
0
349
1
url 오류 질문있습니다
0
211
1
ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out
0
372
1
sudo certbot --nginx 에러
0
1274
2
Minified React error 콘솔에러 (hydrate)
0
469
1
카카오 공유했을 때 이전에 작성했던 글이 나오는 버그
0
247
1
프론트서버 배포 후 EADDRINUSE에러 발생
0
326
1
npm run build 에러
0
518
1
front 서버 npm run build 중에 발생한 에러들
0
381
1
서버 실행하고 브라우저로 들어갔을때 404에러
0
338
2
css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.
0
287
1
팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.
0
237
2
해시태그 검색에서 throttle에 관해 질문있습니다.
0
201
1





