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 ( import (
"embed" "embed"
"html/template" "html/template"
"io"
"io/fs" "io/fs"
"github.com/sirupsen/logrus"
) )
var ( var (
@ -14,11 +17,21 @@ var (
//go:embed *.html //go:embed *.html
templatesFS embed.FS templatesFS embed.FS
Templates *template.Template 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() { func init() {
t := template.New("").Funcs(funcs)
var err error var err error
Templates, err = template.ParseFS(templatesFS, "*") Templates, err = t.ParseFS(templatesFS, "*")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -28,3 +41,23 @@ func init() {
panic(err) 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> <title>Lock Server</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <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> </head>
<body> <body>

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
echo "github.com/labstack/echo/v4" echo "github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
"git.janky.solutions/finn/lockserver/db" "git.janky.solutions/finn/lockserver/db"
"git.janky.solutions/finn/lockserver/frontend" "git.janky.solutions/finn/lockserver/frontend"
@ -22,6 +23,10 @@ type indexTemplateData struct {
} }
func indexHandler(c echo.Context) error { 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() queries, dbc, err := db.Get()
if err != nil { if err != nil {
return err return err

View file

@ -76,7 +76,7 @@ func accessLogMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
if err != nil { if err != nil {
log = log.WithError(err) log = log.WithError(err)
} }
log.Info("request handled") log.Debug("request handled")
return err return err
} }