open-nomad/ui/app/serializers/node.js
Michael Lange 967d3a2e8e In dev mode, mask the local node port to 4200
This allows for local development with the client end points for the node
running on localhost.
2017-10-17 10:17:41 -07:00

38 lines
875 B
JavaScript

import Ember from 'ember';
import ApplicationSerializer from './application';
const { inject } = Ember;
export default ApplicationSerializer.extend({
config: inject.service(),
attrs: {
httpAddr: 'HTTPAddr',
},
normalize(modelClass, hash) {
// Proxy local agent to the same proxy express server Ember is using
// to avoid CORS
if (this.get('config.isDev') && hash.HTTPAddr === '127.0.0.1:4646') {
hash.HTTPAddr = '127.0.0.1:4200';
}
return this._super(modelClass, hash);
},
extractRelationships(modelClass, hash) {
const { modelName } = modelClass;
const nodeURL = this.store
.adapterFor(modelName)
.buildURL(modelName, this.extractId(modelClass, hash), hash, 'findRecord');
return {
allocations: {
links: {
related: `${nodeURL}/allocations`,
},
},
};
},
});