일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 고양이
- 벌루닝
- 딸꾹질멈추는법
- 초코만두
- 건강정보
- 딸꾹질
- 라떼이야기
- 탄수화물소화
- 딸꾹질대처법
- 감기약
- 자연의과학
- 에스프레소샷
- 거미줄의비밀
- 디저트아이디어
- 딸꾹질원인
- 터미널사진사이즈변경
- 면접준비
- 의약품안전
- 피스타치오라떼
- 카페일상
- 식곤증
- 생물학습
- 만두레시피
- 터미널사진편집
- 거미
- 창의적인요리
- 한외마약
- 코포나시럽
- 고양이귀여움
- 내일부터출근
- Today
- Total
SP'S SPARKING
[해결] Access to XMLHttpRequest 에러 본문
발단
Register 구현하려고 POST 썼는데,
I tried to use POST for implementing the 'Register' feature, but
전개
"Access to XMLHttpRequest at 'http://localhost:3000/users/signup' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
에러가 떴다. 이것저것 찾아보다
I got this error, so I had searching for that
힌트
header("Access-Control-Allow-Origin: http://localhost:4200");
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header("Access-Control-Allow-Headers: Content-Type, Authorization");
를 써야 한다고 한다. 어디에 이 코드에 적용해야 할지 잘 모르겠다.
It said I need to put this code, but I wasn't sure which line should I put this code line
그래서 GitHub에 이 코드를 쓴 프로젝트를 찾아봤다.
So, I was searching for some projects that used this code on Github
var app = express();
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
대충 이런 식으로 쓴 것을 확인했다. server 실행할 때 필요한 파일에 넣는다는 것을 알았다. (나의 경우엔 app.js)
I checked some projects that use code like that. They used that code on the file that needs for the server-side started to run (In my case, it was app.js).
결말
수정하고 server 쪽을 다시 npm start 하니까 됐다 :)
After I update it and re-start the server, it works well :)
'HAPPYHACKING > ERROR SOLVED' 카테고리의 다른 글
[SOLVED] HEROKU ERROR H10 status 503: Checking what error it is (0) | 2022.10.06 |
---|---|
[해결] aws ecr get-login-password -> Unable to parse config file: (0) | 2022.07.28 |
[해결] this version of the Java Runtime only recognizes class file versions up to 52.0 (0) | 2022.07.28 |
[해결] "this.custRepository" is null (0) | 2022.07.28 |
[해결] Heroku "npm ERR! Missing: '' from lock file" error (0) | 2022.07.28 |