ui: Remove settings.findHeaders now we can use promises in our adapters (#7375)
Previously the API around setting headers wasn't within a Promised like code path, so we needed a little 'cheat' function to get a token from localStorage syncronously. Since we refactored our adapter layer, we now have a Promised codepath where we need to access this localStorage value and set our headers. This means we can remove our little 'cheat' function.
This commit is contained in:
parent
a9898fcf58
commit
b2f84299ca
|
@ -126,13 +126,16 @@ export default Service.extend({
|
|||
// with whats left after the line, use for the headers
|
||||
const [url, ...headerParts] = urlParts.join(' ').split('\n');
|
||||
|
||||
return client.settings.findBySlug('token').then(function(token) {
|
||||
const headers = {
|
||||
// default to application/json
|
||||
...{
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
// add any application level headers
|
||||
...get(client, 'settings').findHeaders(),
|
||||
...{
|
||||
'X-Consul-Token': typeof token.SecretID === 'undefined' ? '' : token.SecretID,
|
||||
},
|
||||
// but overwrite or add to those from anything in the specific request
|
||||
...createHeaders(headerParts),
|
||||
};
|
||||
|
@ -212,6 +215,7 @@ export default Service.extend({
|
|||
return $.ajax(options);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
abort: function(id = null) {
|
||||
this.connections.purge();
|
||||
|
|
|
@ -4,18 +4,6 @@ const SCHEME = 'consul';
|
|||
const storage = getStorage(SCHEME);
|
||||
export default Service.extend({
|
||||
storage: storage,
|
||||
findHeaders: function() {
|
||||
// TODO: if possible this should be a promise
|
||||
// TODO: Actually this has nothing to do with settings it should be in the adapter,
|
||||
// which probably can't work with a promise based interface :(
|
||||
const token = this.storage.getValue('token');
|
||||
// TODO: The old UI always sent ?token=
|
||||
// replicate the old functionality here
|
||||
// but remove this to be cleaner if its not necessary
|
||||
return {
|
||||
'X-Consul-Token': typeof token.SecretID === 'undefined' ? '' : token.SecretID,
|
||||
};
|
||||
},
|
||||
findAll: function(key) {
|
||||
return Promise.resolve(this.storage.all());
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue