mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-05-30 18:11:07 +00:00
Add network state to UI (#128)
This commit is contained in:
committed by
Maciej Hirsz
parent
1058cd965c
commit
8fa36118b5
@@ -1,7 +1,10 @@
|
||||
import * as http from 'http';
|
||||
import * as url from 'url';
|
||||
import * as WebSocket from 'ws';
|
||||
import Node from './Node';
|
||||
import Feed from './Feed';
|
||||
import Aggregator from './Aggregator';
|
||||
import {Types} from '@dotstats/common';
|
||||
|
||||
const WS_PORT_TELEMETRY_SERVER = Number(process.env.TELEMETRY_SERVER || 1024);
|
||||
const WS_PORT_FEED_SERVER = Number(process.env.FEED_SERVER || 8080);
|
||||
@@ -47,3 +50,23 @@ logClients();
|
||||
telemetryFeed.on('connection', (socket: WebSocket) => {
|
||||
aggregator.addFeed(new Feed(socket));
|
||||
});
|
||||
|
||||
http.createServer((request, response) => {
|
||||
const incoming_url = request.url || "";
|
||||
const parsed_url = url.parse(incoming_url, true);
|
||||
const path = decodeURI(parsed_url.path || "");
|
||||
if (path.startsWith("/network_state/")) {
|
||||
const [chainLabel, strNodeId] = path.split('/').slice(2);
|
||||
const chain = aggregator.getExistingChain(chainLabel as Types.ChainLabel);
|
||||
if (chain) {
|
||||
const nodeList = Array.from(chain.nodeList());
|
||||
const nodeId = Number(strNodeId);
|
||||
const node = nodeList.filter((node) => node.id == nodeId)[0];
|
||||
if (node) {
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
response.write(node.networkState);
|
||||
}
|
||||
}
|
||||
}
|
||||
response.end();
|
||||
}).listen(8081);
|
||||
|
||||
Reference in New Issue
Block a user