susee
This commit is contained in:
parent
5fd6c7b0b5
commit
a3c7c80d8c
@ -13,7 +13,14 @@ exports.APIstatus = async (req, res) =>
|
||||
try
|
||||
{
|
||||
// call token api
|
||||
token_data = await TestHelper.TokenAPI();
|
||||
token = await TestHelper.NewToken();
|
||||
token_data = {};
|
||||
if (token) {
|
||||
token_data = {'status':200,'message':"success",'data':token}
|
||||
}
|
||||
else {
|
||||
token_data = {'status':404,'message':"failed",'data':"No data"}
|
||||
}
|
||||
// store api status only
|
||||
apiArr = [ ];
|
||||
// store server status only
|
||||
@ -22,6 +29,7 @@ exports.APIstatus = async (req, res) =>
|
||||
dbArr = [ ];
|
||||
// store fail status only
|
||||
StatusFailArr = [ ];
|
||||
console.log(process.env.STATUSARRAY);
|
||||
ApiData = await JSON.parse(process.env.STATUSARRAY);
|
||||
if (token_data.status == 200) { apiArr.push({ "Api" : "Token API" , "StatusCode" : token_data.status , "Status" : "Up"}); }
|
||||
else { apiArr.push({ "Api" : "Token API" , "StatusCode" : token_data.status || 502 , "Status" : "Down"}); StatusFailArr.push(token_data.status) }
|
||||
@ -30,16 +38,10 @@ exports.APIstatus = async (req, res) =>
|
||||
reqObj = { };
|
||||
URL = object.url;
|
||||
request_object = object.requestObject;
|
||||
if (object.header == 1 && token_data.status == 200) { request_header = "Bearer"+" "+token_data.data.token; reqObj = {url: URL, method: object.method,json: true,body: request_object,headers : { 'Content-Type' : 'application/json' , 'Authorization' : request_header }} }
|
||||
if (object.header == 1 && token_data.status == 200) { request_header = "Bearer"+" "+token; reqObj = {url: URL, method: object.method,json: true,body: request_object,headers : { 'Content-Type' : 'application/json' , 'Authorization' : request_header }} }
|
||||
else {
|
||||
if (object.name == "SMC Front End")
|
||||
{
|
||||
reqObj = {url: URL,method: object.method}
|
||||
}
|
||||
else
|
||||
{
|
||||
reqObj = {url: URL,method: object.method,json: true,body: request_object}
|
||||
}
|
||||
if (object.name == "SMC Front End") { reqObj = {url: URL,method: object.method} }
|
||||
else { reqObj = {url: URL,method: object.method,json: true,body: request_object} }
|
||||
}
|
||||
request(reqObj, async function (error, response, body) {
|
||||
// because some times some api's could not send respond
|
||||
@ -91,7 +93,15 @@ exports.SingleApiStatus = async (req, res) =>
|
||||
ApiName = req.body.api;
|
||||
ApiData = JSON.parse(process.env.STATUSARRAY);
|
||||
// call token api
|
||||
token_data = await TestHelper.TokenAPI();
|
||||
// token_data = await TestHelper.TokenAPI();
|
||||
token = await TestHelper.NewToken();
|
||||
token_data = {};
|
||||
if (token) {
|
||||
token_data = {'status':200,'message':"success",'data':token}
|
||||
}
|
||||
else {
|
||||
token_data = {'status':404,'message':"failed",'data':"No data"}
|
||||
}
|
||||
if (ApiName == "Token API")
|
||||
{
|
||||
if (token_data.status == 200) { res.send({ "Api" : "Token API" , "StatusCode" : token_data.status , "Status" : "Up" , "success" : true}) }
|
||||
@ -106,17 +116,11 @@ exports.SingleApiStatus = async (req, res) =>
|
||||
reqObj = { };
|
||||
URL = object.url;
|
||||
request_object = object.requestObject;
|
||||
if (object.header == 1 && token_data.status == 200) { request_header = "Bearer"+" "+token_data.data.token; reqObj = {url: URL, method: object.method,json: true,body: request_object,headers : { 'Content-Type' : 'application/json' , 'Authorization' : request_header }} }
|
||||
if (object.header == 1 && token_data.status == 200) { request_header = "Bearer"+" "+token; reqObj = {url: URL, method: object.method,json: true,body: request_object,headers : { 'Content-Type' : 'application/json' , 'Authorization' : request_header }} }
|
||||
else
|
||||
{
|
||||
if (object.name == "SMC Front End")
|
||||
{
|
||||
reqObj = {url: URL,method: object.method}
|
||||
}
|
||||
else
|
||||
{
|
||||
reqObj = {url: URL,method: object.method,body: request_object,json: true}
|
||||
}
|
||||
if (object.name == "SMC Front End") { reqObj = {url: URL,method: object.method} }
|
||||
else { reqObj = {url: URL,method: object.method,body: request_object,json: true} }
|
||||
}
|
||||
request(reqObj, function (error, response, body) {
|
||||
if (response == undefined)
|
||||
@ -143,3 +147,9 @@ exports.SingleApiStatus = async (req, res) =>
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -24,6 +24,31 @@ function TokenAPI()
|
||||
}
|
||||
|
||||
|
||||
function NewToken()
|
||||
{
|
||||
try
|
||||
{
|
||||
URL = process.env.LOGIN_API;
|
||||
request_object = { userId: process.env.LOGINAPIUSERID, password : process.env.LOGINAPIPASSWORD };
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: URL,
|
||||
method: "POST",
|
||||
json: true,
|
||||
body: request_object ,
|
||||
}, function (error, response, body){
|
||||
resolve(body);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function HTML( req , res , apiStatusArr , serverStatusArr , dbStatusArr , apiFailStatusArr )
|
||||
{
|
||||
try
|
||||
@ -50,5 +75,6 @@ function HTML( req , res , apiStatusArr , serverStatusArr , dbStatusArr , apiFai
|
||||
module.exports = {
|
||||
|
||||
TokenAPI : TokenAPI,
|
||||
HTML : HTML
|
||||
HTML : HTML,
|
||||
NewToken : NewToken
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user