hess8
January 15, 2024, 5:32am
1
Hi, in an Ember 3 app there is:
import DS from 'ember-data';
import { computed } from '@ember/object';
export default DS.RESTAdapter.extend({
host: computed(function(){
return 'http://localhost:8000';
}),
namespace: 'api'
});
With DS no longer used, how do write the adapter for Ember 5?
I’m guessing there’s something better than the following?
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import { computed } from '@ember/object';
export default JSONAPIAdapter.extend({
host: computed(function(){
return 'http://localhost:8000';
})
});
hess8
January 15, 2024, 5:43am
2
Or should I instead use
ember server --proxy http://localhost:8000
instead of putting that in the adapter?
hess8
January 15, 2024, 3:09pm
3
So ember server --proxy http://localhost:8000
works for me.
After some reading, it seems the Ember 5 adapter should be
import JSONAPIAdapter from '@ember-data/adapter/json-api';
export default class ApplicationAdapter extends JSONAPIAdapter {
host = 'http://localhost:8000';
}
But that gives me a CORS error. Why does it, while ember server --proxy http://localhost:8000` does not?
proxy makes the server itself proxy which prevents cors considerations from being in play. The adapter approach you need to set the cors headers because the ports are different and thus this will be a cross domain request.
2 Likes