Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a default path for ribbon-webapp ajax requests.
Also, keep a copy of the topology data and provide a getter, so that
you don't have to always use SSE to get topology data.
  • Loading branch information
lance committed Nov 30, 2015
1 parent ce50d71 commit 3594871
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ribbon-webapp/runtime/src/main/resources/ribbon.js
Expand Up @@ -3,7 +3,7 @@ var ribbon = (function() {
var defaultSettings = {
headers: {},
method: 'GET'
};
}, topology = {};

function factory(keycloak) {

Expand All @@ -19,6 +19,7 @@ var ribbon = (function() {
// ensure some default settings exist
settings = settings || defaultSettings;
settings.headers = settings.headers || {};
path = path || '/';

// TODO: Try other URLs if there is more than one server
settings.url = '//' + allServers[0] + path;
Expand Down Expand Up @@ -93,7 +94,7 @@ var ribbon = (function() {
}

function processResponse(request, response) {
if (httpRequest.status === 200) {
if (request.status === 200) {
response.resolve(JSON.parse(request.responseText));
console.log('Response: ' + response.promise.value);
} else {
Expand All @@ -115,14 +116,14 @@ var ribbon = (function() {
}
}

function getJSON(serviceName, url, data) {
return ajax( serviceName, url, {
function getJSON(serviceName, path, data) {
return ajax( serviceName, path, {
data: data
});
}

function postJSON(serviceName, url, data) {
return ajax( serviceName, url, {
function postJSON(serviceName, path, data) {
return ajax( serviceName, path, {
method: 'POST',
data: data
});
Expand All @@ -131,6 +132,7 @@ var ribbon = (function() {
var sse = new EventSource( "/ribbon/system/stream" );
sse.addEventListener('topologyChange', function(message) {
console.log('Ribbon topology changed: ', message.data);
topology = JSON.parse(message.data);
});

sse.onerror = function(e) {
Expand All @@ -145,7 +147,8 @@ var ribbon = (function() {
ajax: ajax,
postJSON: postJSON,
getJSON: getJSON,
topologyEvents: sse
topologyEvents: sse,
getTopology: function() { return topology; }
};
}

Expand Down

0 comments on commit 3594871

Please sign in to comment.