[英]Symfony2 dev server and nelmio cors bundle
我正在用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設置為*以接受任何值,但是必須明確列出允許的方法。 路徑必須至少包含一項。
這是一個簡單的配置:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.