0

I'm using ember data with different URL as i'm moving from ember-rails, to external ember application, so API url is http://localhost:5000 and ember application is http://localhost:9000.

Now the problem is I need to include x-appid and x-app-secret, but whenever add xhr.setRequestHeader() for any of them, the GET request becomes OPTIONS request.

This code was working fine when i was using ember-rails on the same domain, is this the problem or is there something else missing?

ajax: function(url, type, hash) {
    if (this.headers !== undefined) {
      var headers = this.headers;
      if (hash) {
        hash.beforeSend = function (xhr) {
          // Works fine
          xhr.setRequestHeader('Accept', 'application/vnd.vendor+json;version=1');

          // Changes Request from GET to OPTIONS
          xhr.setRequestHeader('x-vendor-appid', '12412412');
          xhr.setRequestHeader('x-vendor-secret', 'aslkdfjaskldfjasd');
        };
      }
    }
    return this._super(url, type, hash);
}

1 Answer 1

1

The browser is sending an OPTIONS request because the domain of the request does not match the domain of your page. This triggers Cross-Origin Resource Sharing (CORS) restrictions.

You need to respond to the CORS request from the server to tell the client it is allowed to make CORS requests to the domain by setting a few HTTP header fields. The browser will then make the original request. I have implemented this with ember.js/rails.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.