Play Framework CORS Headers

后端 未结 3 1803
星月不相逢
星月不相逢 2021-01-02 17:18

I\'m trying to set CORS Headers for my play framework app. Specifically I\'m getting this error

cannot load http://127.0.0.1:9000/. No \'Access-Control-Allow         


        
3条回答
  •  抹茶落季
    2021-01-02 17:26

    I would not recommend writing/using any code to enable CORS which is basically a framework feature and only needs configuration.

    The stuff you copied from the documentation is correct:

    • cors.conf where you modify the play.filters.cors settings. But you seem to have misconfigured something, e.g. the allowedOrigin = * should be configured as null in the config. (Have a look at the documentation page and the linked reference.conf)

    # The allowed origins. If null, all origins are allowed. play.filters.cors.allowedOrigins = null

    • You have correctly enabled the CORSFilter in your Filters.scala
    • Now test your configuration with a correct cURL CORS request:

    curl -H "Origin: http://example.com" \ -H "Access-Control-Request-Method: GET" \ -H "Access-Control-Request-Headers: X-Requested-With" \ -X OPTIONS --verbose \ http://localhost:9000/

提交回复
热议问题