Skip to content
7 changes: 7 additions & 0 deletions client/views/api_backends/view_api_backend/api_status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template name="apiBackendStatus" >

<h2>Status</h2>
<p>Updated: <b id="whenUpdated">..</b></p>
<div id="apiState" class="alert">Checking API status. Hold on..</div>

</template>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ <h1>View API backend</h1>
<h1 class="panel-title">{{apiBackend.name}}</h1>
</div>
<div class="panel-body">
<div class="row">
{{> apiBackendStatus }}
</div>
<div class="row">
<h2>Servers</h2>
<ul class="list-group col-md-3 col-sm-6 col-xs-12">
Expand Down
48 changes: 45 additions & 3 deletions client/views/api_backends/view_api_backend/view_api_backend.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
Template.viewApiBackend.created = function() {

// Create reference to instance
var instance = this;

// Get the API Backend ID from the route
var backendId = Router.current().params.apiBackendId;

// Subscribe to a single API Backend, by ID
instance.subscribe("apiBackend", backendId);
}

};

Template.viewApiBackend.rendered = function () {

// fetches current apiBackend
var apiBackend = ApiBackends.findOne();

// sets up request url based on protocol and host
var url = apiBackend.backend_protocol + "://" + apiBackend.backend_host;

Meteor.call("getApiStatus", url, function (err, status) {

// status object contents:
// status = {
// isUp : <boolean>,
// statusCode : <integer>,
// responseContext : <object>,
// errorMessage : <String>
// };

if (status.isUp) {

// updates layout with success status
$('#apiState').addClass('alert-success').html("API is operating normally.");

}else{

// initial error message
var errorMessage = "API backend is down for some reason. Please contact support.";

// updates layout with success status
$('#apiState').addClass('alert-danger').html(errorMessage);

}

// showing when check did happen
$('#whenUpdated').html("Just now");

});

};
37 changes: 37 additions & 0 deletions server/methods/apiBackendStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Meteor.methods({
'getApiStatus' : function (apiUrl) {

this.unblock();

var status = {
isUp : false,
statusCode : 0,
responseContext : {},
errorMessage : ""
};

try {

// response object from GET request to api host
var result = Meteor.http.call("GET", apiUrl);

// checks is the status code matches 200 and returns boolean
status.isUp = result.statusCode == 200;

// keeps status code value
status.statusCode = result.satusCode;

// keeps the entire response object
status.responseContext = result;

return status;

} catch (error) {

// Got a network error, time-out or HTTP error in the 400 or 500 range.
// keeps error message
status.errorMessage = error;

return status;
}
}});