1
建設使用Rails的REST API的前端界面,我得到的錯誤工作爲Rails後端
XMLHttpRequest cannot load http://www.example.com/questions
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:4200' is therefore not allowed access.
我已經設置了我的適配器是
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
namespace: 'api/v1',
host: 'http://www.example.com'
});
如果我正在構建API,那麼我只包含gem'rack-cors'並允許訪問其他站點,但這不包含在源代碼中。我剛剛開始使用Ember框架,但尚未找到解決此問題的方法。
我試着運行一個代理服務器
ember s --proxy http://www.example.com
,但我得到了同樣的答覆。 RESTAdapter中是否有一件中間件或方法可以繞過此錯誤?
如果你說你無法控制服務器,我認爲唯一的選擇是自己實現一個代理服務器。 – locks
@Coder_Nick你解決了這個問題嗎? – ykaragol