2017-02-07 1 views
-2

에 헤더를 추가 :에 '액세스 제어는 - - 원산지 허용'나는 다음과 같은 오류를 얻을 아우렐 리아 프론트 엔드를 통해 내 API에 액세스하려고하면 아우렐 리아

constructor(Aurelia, HttpClient) { 

    HttpClient.configure(http => { 
     http.withBaseUrl(config.baseUrl); 
    }); 

    this.http = HttpClient; 
    this.app = Aurelia; 

    this.session = JSON.parse(localStorage[config.tokenName] || null); 
    } 

login(username, password) { 

    var client = new HttpClient(); 
    client.createRequest(config.apiUrl + '/auth', { username, password }) 
     .asPost() 
     .withHeader('Access-Control-Allow-Origin', '*') 
     .withBaseUrl(config.baseUrl) 
     .send() 
     .then((response) => response.content) 
     .then((session) => { 
     localStorage[config.tokenName] = JSON.stringify(session); 
     this.session = session; 
     this.app.setRoot('app'); 
    }); 
    } 
:

XMLHttpRequest cannot load https://[my aws API URL here]/auth. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:9000 ' is therefore not allowed access. The response had HTTP status code 403

이 내 코드입니다

내가 뭘 잘못하고 있니?

우편 배달부에서 올바르게 작동합니다.

+4

'Access-Control-Allow-Origin'은 _response_ 헤더로, 데이터를 요청하려는 서버가 보내야합니다. – CBroe

+0

그렇다면 요청이 내 로컬 개발 서버 (localhost : 9000)에서 오지 않았을 때 내 API (AWS API 게이트웨이)가이 헤더를 Postman 앱에서 요청할 때 보내겠습니까? 나는이 모든 것을 처음 접했을 뿐이라는 것을 알고 있습니다. ;) –

+0

브라우저의 개발자 도구에서 특정 요청에 대한 네트워크 로그를 확인하여 확인할 수 있습니다. –

답변

0

AWS API 게이트웨이 인터페이스에서 'CORS 사용'을 사용하고 API를 다시 배포하여 문제를 해결했습니다. 올바른 방향으로 나를 가리켜 주셔서 감사합니다 !!

관련 문제