我正在用symfony开发一个API,当然我已经考虑了cors。我安装了nelmio-cors-bundle,但标头没有到达客户端:
我的配置是这样的:
nelmio_cors:
defaults:
allow_credentials: true
allow_origin: []
allow_headers: []
allow_methods: []
expose_headers: []
max_age: 0
hosts: []
origin_regex: false
paths:
'^/api':
allow_origin: ['*']
allow_headers: ['*']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
max_age: 3600
我得到以下标题:
Allow → GET
Cache-Control → no-cache
Connection → close
Content-Type → application/json
Date → Mon, 16 Mar 2015 03:46:41 GMT
Host → 127.0.0.1:8000
X-Debug-Token → a6ec46
X-Debug-Token-Link → /_profiler/a6ec46
X-Powered-By → PHP/5.5.21
CORS 标头不存在。
你可以帮我吗?我正在symfony的开发服务器中运行我的应用程序,这是一个问题吗?
谢谢。
正如
官方文档中提到的:
allow_origin 和 allow_headers 可以设置为 * 以接受任何值, 但是,必须显式列出允许的方法。路径必须 至少包含一个项目。
这是一个 sapmle 配置:
nelmio_cors:
defaults:
allow_credentials: false
allow_origin: ['^http://localhost:[0-9]+']
allow_headers: ['*']
allow_methods: ['POST', 'GET']
expose_headers: ['*']
max_age: 0
hosts: []
origin_regex: false
forced_allow_origin_value: ~
paths:
'^/':
origin_regex: true
allow_origin: ['^http://localhost:[0-9]+']
allow_headers: ['Authorization']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
max_age: 3600