-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ember-fetch + fastboot + ember-data sadness #38
Comments
I'm running into this exact problem now. My app uses fastboot, ember-data, ember-fetch, and I'm in the process of removing jquery and everything is working, except fastboot fetches with the following error:
this line: 192 ember-fetch/addon/mixins/adapter-fetch.js Lines 183 to 194 in fc5167b
|
@0xadada you can get around this issue with these instructions. |
@nlfurniss unfortunately not because I've also removed jQuery in my app as a dependency, and the |
Did you try adding the initializer to override fastboot per the README? |
I also ran into an nearly identical issue with Ember-fetch's ajaxOption's does not call super, which results in any other extensions of your application adapter not having the opportunity to set headers or anything like that. The current implementation of ember-fetch's ajaxOptions do not allow this to run. This breaks My workaround is to manually set the headers I need after ember-fetch has run: ajaxOptions(...args) {
const options = this._super(...args);
get(this, 'session').authorize(get(this, 'authorizer'), (headerName, headerValue) => {
options.headers[headerName] = headerValue;
});
return options;
}, |
@nlfurniss that worked! I hadn't taken that step, because it wasn't in the README back when i first switched to |
I just want to mention that we are moving fetch support to Ember Data itself : emberjs/data#5386 |
@Duder-onomy I'm running into the same issue (using the same libraries) as you explain above. Curious, would you mind elaborating on where and how you manually set those headers? |
@ehubbell Totally. The latest ember-simple-auth has deprecated authorizers... So I had to change some things a few weeks ago. Now that Because we are using basic auth to protect our staging environment, and we are using fastboot, and simple auth uses the 'Authorization' header, and fastboot will not let us change that default... we had to change the name of our access token key to something that does not use Here is my entire application adapter: import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import AdapterFetch from 'ember-fetch/mixins/adapter-fetch';
import { get } from '@ember/object';
import { inject as service } from '@ember/service';
import config from '../config/environment';
const { JSONAPIAdapter } = DS;
export default JSONAPIAdapter.extend(DataAdapterMixin, AdapterFetch, {
session: service(),
authorizer: 'authorizer:application',
coalesceFindRequests: true,
host: config.APP.apiBase,
namespace: config.APP.apiNamespace,
headers: {
'X-Requested-with': 'XMLHttpRequest',
},
ajaxOptions(...args) {
const options = this._super(...args);
const accessToken = get(this, 'session.data.authenticated.access_token');
options.headers['X-Access-Token'] = accessToken;
options.headers['Content-Type'] = 'application/vnd.api+json';
return options;
},
}); Hope that helps. |
@Duder-onomy Thanks for the help! Turns out I had my |
@nlfurniss sorry, hit delete by accident. Thanks for responding. Looks like it's the right track. I have another error to get past, but its related to a DRF adapter mixin. |
One of my issues is needing to pass HTTPOnly cookies. In my adapter if(fastboot.isFastBoot) {
headers['Cookie'] = fastboot.get('request.headers.cookie');
} |
Solutions!@stefanpenner
re: ☝️ @Duder-onomy your application adapter uses authorizers, which has since become a deprecated pattern in ember-simple-auth.
When used with // app/adapters/application.js
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import AdapterFetchMixin from 'ember-fetch/mixins/adapter-fetch';
import config from 'mir/config/environment';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
export default JSONAPIAdapter.extend(AdapterFetchMixin, {
session: service(),
host: config.DS.host,
namespace: config.DS.namespace,
headers: computed('session.data.authenticated.token', function() {
const headers = {};
headers['Content-Type'] = 'application/vnd.api+json';
if (this.session.isAuthenticated) {
const token = this.session.data.authenticated['access_token'];
headers['Authorization'] = `Bearer ${token}`;
}
return headers;
})
}); I also followed the ember-fetch README, to disable the ajax instance initializer on fastboot: // fastboot/initializers/ajax.js
export default {
name: 'ajax-service',
initialize() {
// noop
// This is to override Fastboot's initializer which prevents ember-fetch from working
// https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/fastboot/initializers/ajax.js
}
} One of the nice benefits of this approach is that it helps paves the way to removing jQuery, especially with |
Note on setting Just sending out a message in a bottle in case anybody picks it up. Your app may be slightly different, so make sure you have a memory leak before changing from a computed to |
@allthesignals ref issue for container memory leaks |
fastboot and fetch share the same extension point in ember-data, and today they do not work together.
Long-term, I suspect fastboot should provide a
XMLHTTPRequest
global, and afetch
global. That way it doesn't interfere in high level code, and would also "just work" with things like pretender/mirage.The text was updated successfully, but these errors were encountered: