From d122d841e8b7dd7f8942b6f2fa84220f95f2cae4 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Wed, 10 Sep 2025 00:46:42 +0100 Subject: Add optional CSS to html --- api/handlers/html.go | 36 ++++++++++++++++++++++++++++++++++++ api/handlers/pong.go | 31 +++++++++++++++++++++++++++++++ api/router.go | 1 + 3 files changed, 68 insertions(+) create mode 100644 api/handlers/pong.go (limited to 'api') diff --git a/api/handlers/html.go b/api/handlers/html.go index dd5d4e8..2f6688c 100644 --- a/api/handlers/html.go +++ b/api/handlers/html.go @@ -7,6 +7,28 @@ import ( "git.leonardobishop.net/history/pkg/html" ) +const style = `` + func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { entries, err := entriesService.GetEntries() @@ -21,6 +43,20 @@ func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) ht return } + if r.URL.Query().Get("css") == "no" { + goto send + } + + html = ` + + +History +` + style + ` + +` + html + ` +` + + send: w.Header().Set("Content-Type", "text/html;charset=UTF-8") w.Write([]byte(html)) } diff --git a/api/handlers/pong.go b/api/handlers/pong.go new file mode 100644 index 0000000..ee0d445 --- /dev/null +++ b/api/handlers/pong.go @@ -0,0 +1,31 @@ +package handlers + +import ( + "net/http" +) + +const pong = ` + + +Pong! + + +
+ _______
+< Pong! >
+ -------
+        \   ^__^
+         \  (oo)\_______
+            (__)\       )\/\
+                ||----w |
+                ||     ||
+
+ +` + +func Pong() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html") + w.Write([]byte(pong)) + } +} diff --git a/api/router.go b/api/router.go index ec7ac4d..c18fed8 100644 --- a/api/router.go +++ b/api/router.go @@ -22,6 +22,7 @@ func NewServer(api ApiServices) *http.ServeMux { mux.HandleFunc("POST /record", middleware.Cors(handlers.RecordEntry(api.EntiresService, api.Config.Token))) mux.HandleFunc("GET /html", handlers.GetEntriesHtml(api.EntiresService, api.HtmlService)) + mux.HandleFunc("GET /", handlers.Pong()) return mux } -- cgit v1.2.3-70-g09d2