working initial prototype

This commit is contained in:
decentral1se 2022-04-22 13:12:28 +02:00
parent 0222caf32e
commit 3f9083f49d
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 41 additions and 9 deletions

View File

@ -7,16 +7,52 @@
<title>Unnamed Project</title>
</head>
<body>
<p>Hello, World!</p>
<p>Home of <span id="nodeID"></></p>
<iframe id="frame" src="" title="listing"></iframe>
<p>Who else is around? (refresh to see new nodes)</p>
<ul id="allnodes">
</ul>
</body>
<script>
// retrieve who we are
var request = new XMLHttpRequest();
request.open('GET', '/api/config', true);
var localData;
request.open("GET", "/api/config", true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response);
localData = JSON.parse(this.response);
var span = document.getElementById("nodeID");
span.textContent = localData.nodeID;
}
// retrieve who is around
var ul = document.getElementById("allnodes");
var request = new XMLHttpRequest();
request.open("GET", "/api/nodes", true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response);
for (var i = 0; i < data.length; i++) {
var a = document.createElement("a");
a.textContent = data[i].nodeID
a.setAttribute("href", "http://" + data[i].addr + ":5555");
var li = document.createElement("li");
li.appendChild(a)
ul.appendChild(li);
if (data[i].nodeID === localData.nodeID) {
var frame = document.getElementById("frame");
frame.setAttribute("src", "http://" + data[i].addr + ":1312");
}
}
}
};
request.send();
};
request.send();
</script>
</html>

View File

@ -219,7 +219,7 @@ func parseAnnouncePacket(size int, addr *net.UDPAddr, packet []byte) (*nodeInfo,
err := json.Unmarshal([]byte(payload), nodeInfo)
nodeInfo.Addr = addr.IP.String()
nodeInfo.NodeID = fmt.Sprintf("%s-%s", nodeInfo.NodeID, nodeInfo.Addr)
nodeInfo.NodeID = fmt.Sprintf("%s", nodeInfo.NodeID)
if err != nil {
return nil, err
}
@ -335,11 +335,7 @@ func dashboardServe(conf *config, nodeList *list.List) {
dashboardMux.HandleFunc("/api/config", configHandler(conf))
dashboardMux.HandleFunc("/api/nodes", nodesHandler(nodeList))
// We don't want the dashboard to be public
address := "localhost"
if conf.Debug {
address = "0.0.0.0"
}
address := "0.0.0.0"
fmt.Printf("Starting dashboard at %s:%v\n", address, conf.FilePort)
err := http.ListenAndServe(fmt.Sprintf("%s:%v", address, conf.FilePort), dashboardMux)