2015-12-21 22 views
2

在我的EVE配置中,我定義了SCHEMA_ENDPOINT='schema',這樣當我執行獲取api_root/schema/resource時,我得到該資源的模式。我也有X_DOMAINS='*',所以當我打電話給api_root/resource/item時,我得到從任何域調用我的API時調用的項目。這兩個現在都分開工作。如何使用EVE中的CORS調用get-up模式端點?

但是,如果我叫api_root/schema/resource甚至只是api_root/schema,這會給我我所有的資源的模式,與CORS,其中發送OPTIONS預檢要求,它失敗的預檢要求。所以,當我做出一個比一個不同的域一個AJAX調用API託管在我的鉻收到此錯誤信息:

XMLHttpRequest cannot load http://api.dev:5000/v1/schema/resource. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://test.dev:5002' is therefore not allowed access.

現在我沒有這個問題與任何其他調用它使用CORS。就像我說的,我在撥打api_root/resource時沒有這個問題。所以我不認爲這是客戶端問題。是否有某種服務器端實現可以使架構端點與CORS一起工作?

UPDATE:

所以發送OPTIONS而不是GET,如果問題。例如:

$ curl -I -X OPTIONS -H "Origin: test.com" 'http://127.0.0.1:5000/v1/schema/order' --verbose 
* Hostname was NOT found in DNS cache 
* Trying 127.0.0.1... 
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0) 
> OPTIONS /v1/schema/order HTTP/1.1 
> User-Agent: curl/7.35.0 
> Host: 127.0.0.1:5000 
> Accept: */* 
> Origin: http://test.com 
> 
* HTTP 1.0, assume close after body 
< HTTP/1.0 200 OK 
< Content-Type: text/html; charset=utf-8 
< Allow: HEAD, OPTIONS, GET 
< Content-Length: 0 
< Server: Eve/0.6.2.dev0 Werkzeug/0.10.4 Python/2.7.6 
< Date: Mon, 11 Jan 2016 16:57:39 GMT 

回答

0

我測試SCHEMA_ENDPOINT與CORS和一切似乎工作正常。在我的設置,我有:

X_DOMAINS = '*' 
SCHEMA_ENDPOINT = 'schema' 

我的飛行前的要求:

curl -H "Origin: http://test.com" --verbose http://localhost:5000/schema 

> GET /schema/contacts HTTP/1.1 
> Host: localhost:5000 
> User-Agent: curl/7.43.0 
> Accept: */* 
> Origin: http://test.com 

< HTTP/1.0 200 OK 
< Access-Control-Allow-Origin: http://test.com 
< Vary: Origin 
< Access-Control-Allow-Headers: 
< Access-Control-Expose-Headers: 
< Access-Control-Allow-Methods: HEAD, OPTIONS, GET 
< Access-Control-Allow-Max-Age: 21600 
< Server: Eve/0.6.2.dev0 Werkzeug/0.10.4 Python/2.7.8 

情況與此相同/schema/resource。請注意,-Headers是空的,因爲在我的測試中,我沒有設置任何X_HEADERS或​​。

編輯:更新後,我看到問題是(是)與OPTIONS。它已經固定在上游,並將在v0.6.2中發佈。

+0

這也適用於我,但問題是發送'OPTIONS'而不是'GET'。我更新了我的問題以反映這一點。 –

+0

查看我的更新回答。 –

+0

@SirNeuman它已被固定在上游 - 答案已更新。謝謝。 –