Skip to content

Commit

Permalink
Merge pull request #74 from planetscale/fix-graph
Browse files Browse the repository at this point in the history
Apply review suggestions on query graph code
  • Loading branch information
systay authored Nov 28, 2024
2 parents 879e7b0 + 79f9174 commit e9ef339
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions go/summarize/force-graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"net"
"net/http"
)

Expand Down Expand Up @@ -67,15 +68,25 @@ func createForceGraphData(s *Summary) forceGraphData {
func renderQueryGraph(s *Summary) {
data := createForceGraphData(s)

// Start the HTTP server
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
serveIndex(w, data)
})
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
}
defer listener.Close()

port := "1010"
fmt.Printf("Server started at http://localhost:%s\n", port)
// Get the assigned port
addr, ok := listener.Addr().(*net.TCPAddr)
if !ok {
exit("could not create a listener")
}
fmt.Printf("Server started at http://localhost:%d\nExit the program with CTRL+C\n", addr.Port)

// Start the server
// nolint: gosec,nolintlint // this is all ran locally so no need to care about vulnerabilities around timeouts
if err := http.ListenAndServe(":"+port, nil); err != nil {
err = http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
serveIndex(w, data)
}))
if err != nil {
exit(err.Error())
}
}
Expand Down

0 comments on commit e9ef339

Please sign in to comment.