From 550e69568ca0cd4ab0b32705dc135b4cc9d4894d Mon Sep 17 00:00:00 2001 From: "raja.blaze" Date: Fri, 9 Aug 2019 15:45:17 +0530 Subject: [PATCH] Get peer issue fixed --- server.ts | 4 +-- server/controllers/BlockchainKernel.ts | 40 +++++++++++++++----------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/server.ts b/server.ts index 12360dc..4c8cff4 100644 --- a/server.ts +++ b/server.ts @@ -76,7 +76,7 @@ app.use(function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, Accept, Authtoken,cookie_id'); - + // intercept OPTIONS method if ('OPTIONS' == req.method) { return res.status(200).end(); @@ -87,7 +87,6 @@ app.use(function(req, res, next) { } ); -app.use(errorMiddleware); app.use(bodyParser.json({ limit: "50mb" })); app.use(bodyParser.urlencoded({ extended: false })); app.use( @@ -111,6 +110,7 @@ controllers.forEach(controller => { app.get("/epic_explorer/v1/**", (req, res) => { res.send({ msg: "Api works." }); }); +app.use(errorMiddleware); // * NOTE :: leave this as require() since this file is built Dynamically from webpack const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require("./server/main"); diff --git a/server/controllers/BlockchainKernel.ts b/server/controllers/BlockchainKernel.ts index fbf2120..71cfcc0 100644 --- a/server/controllers/BlockchainKernel.ts +++ b/server/controllers/BlockchainKernel.ts @@ -516,29 +516,35 @@ export class BlockchainKernelController { ) => { var self = this; try { - http.get('http://116.203.152.58:3413/v1/peers/connected', (resp) => { + http.get('http://116.203.152.58:3413/v1/peers/connected', + async (resp) => { // console.log('resp resp respresp',resp); let data = ''; + let result ; // A chunk of data has been recieved. + await new Promise((resolve) => { resp.on('data', function (chunk) { - data += chunk; - - let dataJson = self.IsJsonString(data); - if(dataJson.length > 0){ + data += chunk; - dataJson.forEach(function (value, i) { - value['id'] = i; - }); - } - response.status(200).json({ - status: 200, - timestamp: Date.now(), - message: 'Peers list fetched successfully', - response: { - dataJson - }, - }); + let dataJson = self.IsJsonString(data); + if(dataJson.length > 0){ + + result = dataJson.map(function (value, i) { + value['id'] = i; + return value; + }); + } + resolve(); + }); + }); + response.status(200).json({ + status: 200, + timestamp: Date.now(), + message: 'Peers list fetched successfully', + response: { + dataJson: result + }, }); }); } catch (error) {