저는 각도 4를 프론트 엔드로 사용하고 laravel (홈 스테이 드 mydomain.test)을 백엔드로 사용합니다.Laravel CORS 오류 (비밀 번호 포함)
barryvdh/laravel-고르 구성 파일 (cors.php 설정 파일) :
return [
/*
|--------------------------------------------------------------------------
| Laravel CORS
|--------------------------------------------------------------------------
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
| to accept any value.
|
*/
'supportsCredentials' => true,
'allowedOrigins' => ['http://localhost:4200'],
'allowedHeaders' => ['Content-Type','Accept'],
'allowedMethods' => ['GET','POST','PUT', 'PATCH', 'OPTION'],
'exposedHeaders' => ['Content-Disposition', 'x-total-count', 'x-filename', '*'],
'maxAge' => 0,
'hosts' => ['*'],
각 4 내가 laravel의 API 백엔드에 각 4에서 쿠키를 보낼 때 오류가 아래 크롬 브라우저에 표시 요청 :
refreshToken(){
const headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer ' + this.getToken()})
let options = new RequestOptions({ headers: headers, withCredentials: true });
return this.http.post(API_DOMAIN + 'refresh', JSON.stringify({}), options)
.map(
(response) => {
console.log(response.json());
return response.json()
},
)
}
브라우저 오류 :
Failed to load http://mydomian.test/api/refresh: 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'. Origin 'http://localhost:4200' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
허용 헤더에 *를 넣으면 안됩니다. 허용 된 모든 요청 헤더를 지정해야합니다. allowHeaders => [ 'Content-Type, Accept']'' –
@DevangNaghera allowedHeaders를 추가했지만 오류가 여전히 존재합니다! – Zione01