debug log all incoming http headers
All checks were successful
/ build-container (push) Successful in 7m23s

trying to figure out how to get baseurl
This commit is contained in:
Finn 2024-04-25 12:06:20 -07:00
parent 22cafb347b
commit d8ebb87191
4 changed files with 41 additions and 3 deletions

View file

@ -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
}

View file

@ -5,7 +5,7 @@
<title>Lock Server</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="/static/main.css" />
<style type="text/css">{{ staticCSS "main.css" }}</style>
</head>
<body>

View file

@ -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

View file

@ -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
}