Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Create UI server
Browse files Browse the repository at this point in the history
  • Loading branch information
kenellorando committed May 16, 2020
1 parent 4273184 commit 4a5fbc0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Receiver(w http.ResponseWriter, r *http.Request) {
// Retriever - gets agent data
func Retriever(w http.ResponseWriter, r *http.Request) {
jsonMarshal, _ := json.Marshal(system)
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
w.Write(jsonMarshal)
}
30 changes: 30 additions & 0 deletions web/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"net/http"
"path"

"github.com/gorilla/mux"
"github.com/kenellorando/clog"
)

func main() {
// Handle routes
r := mux.NewRouter()

//
r.PathPrefix("/css/").Handler(http.StripPrefix("/css/", http.FileServer(http.Dir("./public/css/"))))
r.PathPrefix("/js/").Handler(http.StripPrefix("/js/", http.FileServer(http.Dir("./public/js/"))))
r.HandleFunc("/", ServeRoot).Methods("GET")

// Start server
clog.Info("main", fmt.Sprintf("Starting webserver on port <%s>.", ":8900"))
clog.Fatal("main", "Server failed to start!", http.ListenAndServe(":8900", r))
}

// ServeRoot - serve the homepage
func ServeRoot(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "text/html")
http.ServeFile(w, r, path.Dir("./public/index.html"))
}
33 changes: 33 additions & 0 deletions web/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Melody</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function () {getReport();}, 0);
setInterval(function () {getReport();}, 1000)
})

function getReport() {
$.ajax({
type: 'GET',
url: 'https://api.melody.systems/api/v0.1/getreport',
success: function(data) {
console.log(data);
document.getElementById("rawoutput").innerHTML = data;
}
})
}

</script>
</head>
<body>
<h1>Melody</h1>
<p>Systems Infrastructure Monitor</p>

<div id="rawoutput"></div>
</body>
</html>

0 comments on commit 4a5fbc0

Please sign in to comment.