죠부니 2018. 8. 9. 11:54
반응형

1. 에러

Failed to load http://AAAA: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://BBB' is therefore not allowed access. The response had HTTP status code 404.

2. 원인

현재 도메인과 다른 도메인에서 리소스가 요청될경우 보안상으 이유로 데이터를 받을 수 없다.
RESTful API기반으로 통신할때 API서버와 웹서버의 페이지가 달라서 CORS제한이 걸리게된다.



CORS : Cross Origin Resource Sharing

3. 해결

현재 nodejs에서 express를 사용중이다.

https://www.npmjs.com/package/cors


cors를 통하거나 직접 응답헤더에서 추가하면된다.

$ npm install cors


var express = require('express')
var cors = require('cors')
var app = express()
 
app.use(cors())


반응형