简体   繁体   中英

Not able to call my api throwing error Disallowed for cross-origin requests that require preflight

Hey I am new to ember and frontend thing.My backend is designed using django.All my api endpoint ends with " / "(ex: 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 " and leaves the end " / ".

some codes snippet are:

routes.js:

return this.store.findRecord('feed');

model name is feed.

adapter.js:

host:"http://example.com/api",
headers:{'authorization:"abc"}

THE ERROR IN CONSOLE IS:

The request was redirected to ' http://example.com/api/feed/ ', which is disallowed for cross-origin requests that require preflight.

So it is redirecting to correct api end point but cors is not allowing the requests to happen.

Is there a way to call the api with " / "at end through ember.

Override your buildURL method in your adapter. Example for RESTAdapter:

DS.RESTAdapter.extend({
  buildURL (modelName, id, snapshot, requestType, query) {
    return this._super(modelName, id, snapshot, requestType, query) + '/';
  }
})

You could probably also refactor this to use arguments instead of explicitly specyfing each param.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM