我正在使用 ember-cli。需要调用远程服务器,我无法控制 API,并且 API 上没有设置 CORS。
我正在努力设置代理服务器。理想情况下,我喜欢使用 ember-cli 内置的东西。我见过代理选项“ember serve --proxy”,但我不知道如何使用它。
我基本上想做:
Ember.$.ajax('https://www.somewhere.com/api/v1/data/plans', {
"type": 'POST',
"dataType": 'JSON',
"data": {
"name": "My delivery plan",
"date": "2013/11/20",
"distance_unit": "mi"
}, // End data payload
"success": function (data, textStatus, jqXHR) {
return data;
},
"error": function (jqXHR, textStatus, errorThrown) {
window.console.log(jqXHR);
}
});
当我这样做时,我得到:
XMLHttpRequest cannot load https://www.somewhere.com/api/v1/data/plans. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
也在研究 nginx,但我不知道如何在本地设置它或如何让它与 ember-cli 服务器一起工作。
任何帮助深表感谢!
谢谢