Refactor HTML structure and styles; implement dynamic serving of CSS and JS files

This commit is contained in:
2025-06-14 04:58:23 +02:00
parent e901de46e9
commit 6d5fc75719
4 changed files with 450 additions and 366 deletions
+18 -9
View File
@@ -163,7 +163,24 @@ func main() {
http.HandleFunc("/api/profiles", profilesHandler)
http.HandleFunc("/api/history", historyHandler)
http.HandleFunc("/", serveHTML)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "text/html")
http.ServeFile(w, r, "index.html")
})
http.HandleFunc("/style.css", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
http.ServeFile(w, r, "style.css")
})
http.HandleFunc("/script.js", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
http.ServeFile(w, r, "script.js")
})
log.Println("Server is starting on port 3000...")
log.Fatal(http.ListenAndServe(":3000", nil))
@@ -298,11 +315,3 @@ func fetchProfile(url string, displayName string) (*ProfileData, error) {
})
return profile, nil
}
func serveHTML(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
http.ServeFile(w, r, "index.html")
}