1

我正在使用 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 服务器一起工作。

任何帮助深表感谢!

谢谢

4

1 回答 1

-1

我认为nginx这是执行此操作的方法,您可以在此处遵循这个开放的拉取请求,以了解它是如何工作的。

当我得到更全面的信息时,我会尝试更新这个答案,但这应该是一个很好的起点。

于 2014-06-01T21:10:00.813 回答