mirror of
https://github.com/status-im/consul.git
synced 2025-02-08 20:05:09 +00:00
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
f0ce300204
commit
bda515abe9
@ -126,13 +126,16 @@ export default Service.extend({
|
|||||||
// with whats left after the line, use for the headers
|
// with whats left after the line, use for the headers
|
||||||
const [url, ...headerParts] = urlParts.join(' ').split('\n');
|
const [url, ...headerParts] = urlParts.join(' ').split('\n');
|
||||||
|
|
||||||
|
return client.settings.findBySlug('token').then(function(token) {
|
||||||
const headers = {
|
const headers = {
|
||||||
// default to application/json
|
// default to application/json
|
||||||
...{
|
...{
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
},
|
},
|
||||||
// add any application level headers
|
// 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
|
// but overwrite or add to those from anything in the specific request
|
||||||
...createHeaders(headerParts),
|
...createHeaders(headerParts),
|
||||||
};
|
};
|
||||||
@ -212,6 +215,7 @@ export default Service.extend({
|
|||||||
return $.ajax(options);
|
return $.ajax(options);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
abort: function(id = null) {
|
abort: function(id = null) {
|
||||||
this.connections.purge();
|
this.connections.purge();
|
||||||
|
@ -4,18 +4,6 @@ const SCHEME = 'consul';
|
|||||||
const storage = getStorage(SCHEME);
|
const storage = getStorage(SCHEME);
|
||||||
export default Service.extend({
|
export default Service.extend({
|
||||||
storage: storage,
|
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) {
|
findAll: function(key) {
|
||||||
return Promise.resolve(this.storage.all());
|
return Promise.resolve(this.storage.all());
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user