0

I am new to ember js using version 3. From a route I am using this line this.get('store').findAll('users');

Instead of setting HTTP method GET, it is setting HTTP method OPTIONS.

Because of server is getting OPTIONS as HTTP method, server side i am getting error.

io.katharsis.errorhandling.exception.MethodNotFoundException: OPTIONS: /users/

and in browser I am getting this error

Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

I am having the below code in application adapter and @CrossOrigin(origins="*") on Spring Rest API side.

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({

init() {
    this._super(...arguments);

    this.set('headers', {
      'Access-Control-Allow-Origin': '*'
    });
  },

  host: 'http://localhost:8082',
  namespace: 'spring-katharsis'
});

If the request contain HTTP method GET, I think it may solve the issue.

Please help on this.

Idriss Neumann
  • 3,760
  • 2
  • 23
  • 32
user1346346
  • 195
  • 2
  • 16
  • Have you tried authenticating at the remote end, before making the GET call? I think you are getting a "handshake" request at first, where you get the chance to authenticate - that's the OPTIONS call. If you authenticate beforehand, you should get past it while testing. – Culme Jun 20 '18 at 11:42
  • I have not authenticated at the remote end. I am trying to do CRUD in Ember 3 with Rest API on server side which follow the JSON API. For server side i follow this https://dzone.com/articles/json-api-using-katharsis-amp-spring-boot – user1346346 Jun 20 '18 at 12:00
  • When using CORS an OPTIONS preflight request is normal. Your server should work with that. Do you really *need* CORS? Often you dont and its just pain. – Lux Jun 20 '18 at 12:18
  • this.set('headers', { 'Access-Control-Allow-Origin': '*', "Access-Control-Allow-Credentials", "true", "Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT", "Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers" }); Set all these to header – Sumesh TG Jun 20 '18 at 12:57
  • It's called [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). You just need to configure your API to response to OPTIONS request. How to do this for spring was discussed [here](https://stackoverflow.com/questions/33331042/how-to-handle-http-options-requests-in-spring-boot) – Gennady Dogaev Jun 20 '18 at 14:38
  • @Lux Ember is running on http://localhost:4200 and Spring boot is running on http://localhost:8889/spring-katharsis/api/departments – user1346346 Jun 21 '18 at 04:14
  • @Sumesh TG, i tried by setting this headers, did not solve the issue. – user1346346 Jun 21 '18 at 04:17
  • turn of CORS in server – Sumesh TG Jun 21 '18 at 08:59
  • why not use the ember proxy for development? `ember s --proxy=http://localhost:8889` would allow you to drop cors. The question is how your production environment will look like. But then you probably will use spring to serve ember so no CORS as well. – Lux Jun 21 '18 at 15:45

0 Answers0