From d8ebb87191f7c6401c6551d56928f85210c7627a Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 25 Apr 2024 12:06:20 -0700 Subject: [PATCH] debug log all incoming http headers trying to figure out how to get baseurl --- frontend/frontend.go | 35 ++++++++++++++++++++++++++++++++++- frontend/index.html | 2 +- httpserver/index.go | 5 +++++ httpserver/server.go | 2 +- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/frontend/frontend.go b/frontend/frontend.go index 8ea3a13..2f67754 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -3,7 +3,10 @@ package frontend import ( "embed" "html/template" + "io" "io/fs" + + "github.com/sirupsen/logrus" ) var ( @@ -14,11 +17,21 @@ var ( //go:embed *.html templatesFS embed.FS Templates *template.Template + + funcs = template.FuncMap{ + "static": staticFn, + "staticCSS": func(filename string) (template.CSS, error) { + data, err := staticFn(filename) + return template.CSS(data), err + }, + } ) func init() { + t := template.New("").Funcs(funcs) + var err error - Templates, err = template.ParseFS(templatesFS, "*") + Templates, err = t.ParseFS(templatesFS, "*") if err != nil { panic(err) } @@ -28,3 +41,23 @@ func init() { panic(err) } } + +func staticFn(filename string) (string, error) { + f, err := Static.Open(filename) + if err != nil { + return "", err + } + defer f.Close() + + data, err := io.ReadAll(f) + if err != nil { + return "", err + } + + logrus.WithFields(logrus.Fields{ + "filename": filename, + "data": string(data), + }).Debug("reading static file for template") + + return string(data), nil +} diff --git a/frontend/index.html b/frontend/index.html index 96a08e0..f44f800 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -5,7 +5,7 @@ Lock Server - + diff --git a/httpserver/index.go b/httpserver/index.go index fbf6b0c..a9b02cd 100644 --- a/httpserver/index.go +++ b/httpserver/index.go @@ -5,6 +5,7 @@ import ( "errors" echo "github.com/labstack/echo/v4" + "github.com/sirupsen/logrus" "git.janky.solutions/finn/lockserver/db" "git.janky.solutions/finn/lockserver/frontend" @@ -22,6 +23,10 @@ type indexTemplateData struct { } func indexHandler(c echo.Context) error { + for k, v := range c.Request().Header { + logrus.WithFields(logrus.Fields{"header": k, "value": v}).Debug("request header") + } + queries, dbc, err := db.Get() if err != nil { return err diff --git a/httpserver/server.go b/httpserver/server.go index 6b01e18..e45530a 100644 --- a/httpserver/server.go +++ b/httpserver/server.go @@ -76,7 +76,7 @@ func accessLogMiddleware(next echo.HandlerFunc) echo.HandlerFunc { if err != nil { log = log.WithError(err) } - log.Info("request handled") + log.Debug("request handled") return err }