1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/adapters/base.js
Kevin Ansfield 604fda4348 Update package.json details, rename module to ghost-admin
no issue
- updates `package.json` details to better reflect the separation from the `Ghost` package
- update ember config and all import statements to reflect the new `ghost-admin` module name in `package.json`
2016-06-03 16:12:54 +01:00

60 lines
1.4 KiB
JavaScript

import Ember from 'ember';
import RESTAdapter from 'ember-data/adapters/rest';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import config from 'ghost-admin/config/environment';
const {
inject: {service}
} = Ember;
export default RESTAdapter.extend(DataAdapterMixin, {
authorizer: 'authorizer:oauth2',
host: window.location.origin,
namespace: ghostPaths().apiRoot.slice(1),
session: service(),
headers: {
'X-Ghost-Version': config.APP.version
},
shouldBackgroundReloadRecord() {
return false;
},
query(store, type, query) {
let id;
if (query.id) {
id = query.id;
delete query.id;
}
return this.ajax(this.buildURL(type.modelName, id), 'GET', {data: query});
},
buildURL() {
// Ensure trailing slashes
let url = this._super(...arguments);
if (url.slice(-1) !== '/') {
url += '/';
}
return url;
},
handleResponse(status) {
if (status === 401) {
if (this.get('session.isAuthenticated')) {
this.get('session').invalidate();
return; // prevent error from bubbling because invalidate is async
}
}
return this._super(...arguments);
}
});