2017-12-07 1 views
0

내가이 애플 리케이션이 있습니다플레이 프레임 워크 CORS 요청

  1. 재생 로컬 호스트에서 실행 2.6.7 응용 프로그램 : 9000
  2. 웹팩 dev에 서버 로컬 호스트에서 실행 : 3000 개

웹팩 응용 프로그램 차종을 재생 응용 프로그램은

로 응답되는 재생 응용 프로그램

$.ajax({ 
    url: 'http://localhost:9000/users', 
    data: JSON.stringify(data), 
    dataType: 'json', 
    method: 'POST' 
}) 

에 POST 요청 내가 명시 적으로 요청이 오류없이 통과 않습니다

def create = Action { 
    Ok("stuff").withHeaders(
    "Access-Control-Allow-Origin" -> "http://localhost:3000" 
) 
} 

으로 재생 응용 프로그램에서 헤더를 설정 만

Failed to load http://localhost:9000/users: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. 

.

제 질문은 : docs이 제안하는 것처럼 Play가이 헤더를 자동으로 설정하지 않는 이유는 무엇입니까? 내 application.conf은 빈 파일입니다.

답변

0

CORS 필터는 기본적으로 활성화되어 있지 않습니다. application.conf에

play.filters.enabled += play.filters.cors.CORSFilter 

를 추가하면이 문제를 해결