无法调用我的 api 抛出错误不允许需要预检的跨域请求
Not able to call my api throwing error Disallowed for cross-origin requests that require preflight
嘿,我是 ember 的新手,前端 thing.My 后端是使用 django.All 设计的,我的 api 端点以“/”结尾(例如:http://example.com/api/feed/).Now when I call this api's from ember app.It send the requests to "http://example.com/api/feed" 并留下末尾的 " / "。
一些代码片段是:
routes.js:
return this.store.findRecord('feed');
模型名称是 feed。
adapter.js:
host:"http://example.com/api",
headers:{'authorization:"abc"}
控制台中的错误是:
请求被重定向到“http://example.com/api/feed/”,这对于需要预检的跨域请求是不允许的。
所以它正在重定向到正确的 api 终点,但 cors 不允许请求发生。
有没有办法通过 ember.
调用末尾带有“ / ”的 api
重写适配器中的 buildURL
方法。 RESTAdapter 示例:
DS.RESTAdapter.extend({
buildURL (modelName, id, snapshot, requestType, query) {
return this._super(modelName, id, snapshot, requestType, query) + '/';
}
})
您也可以重构它以使用 arguments
而不是显式指定每个参数。
嘿,我是 ember 的新手,前端 thing.My 后端是使用 django.All 设计的,我的 api 端点以“/”结尾(例如:http://example.com/api/feed/).Now when I call this api's from ember app.It send the requests to "http://example.com/api/feed" 并留下末尾的 " / "。
一些代码片段是:
routes.js:
return this.store.findRecord('feed');
模型名称是 feed。
adapter.js:
host:"http://example.com/api",
headers:{'authorization:"abc"}
控制台中的错误是:
请求被重定向到“http://example.com/api/feed/”,这对于需要预检的跨域请求是不允许的。
所以它正在重定向到正确的 api 终点,但 cors 不允许请求发生。
有没有办法通过 ember.
调用末尾带有“ / ”的 api重写适配器中的 buildURL
方法。 RESTAdapter 示例:
DS.RESTAdapter.extend({
buildURL (modelName, id, snapshot, requestType, query) {
return this._super(modelName, id, snapshot, requestType, query) + '/';
}
})
您也可以重构它以使用 arguments
而不是显式指定每个参数。