fix: Stringify network state on demand (#146)

This commit is contained in:
Maciej Hirsz
2019-05-14 15:19:00 +02:00
committed by GitHub
parent 74c784c62d
commit 4a48a6eecf
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -62,9 +62,11 @@ http.createServer((request, response) => {
const nodeList = Array.from(chain.nodeList());
const nodeId = Number(strNodeId);
const node = nodeList.filter((node) => node.id == nodeId)[0];
if (node && typeof node.networkState === 'string') {
if (node && node.networkState) {
const { networkState } = node;
response.writeHead(200, {"Content-Type": "application/json"});
response.write(node.networkState);
response.write(typeof networkState === 'string' ? networkState : JSON.stringify(networkState));
} else {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Node has disconnected or has not submitted its network state yet");