aboutsummaryrefslogtreecommitdiff
path: root/backend/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/router.go')
-rw-r--r--backend/router.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/backend/router.go b/backend/router.go
index 8ed63fa..374e28b 100644
--- a/backend/router.go
+++ b/backend/router.go
@@ -1,6 +1,7 @@
package backend
import (
+ "context"
"embed"
"io/fs"
"log/slog"
@@ -19,7 +20,7 @@ const Version = "0.1.0"
//go:embed templates
var templates embed.FS
-func NewRouter(debug bool) *chi.Mux {
+func NewRouter(debug bool, cfg *Config) *chi.Mux {
logFormat := httplog.SchemaECS.Concise(!debug)
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
@@ -49,6 +50,12 @@ func NewRouter(debug bool) *chi.Mux {
LogRequestHeaders: []string{"Origin"},
LogResponseHeaders: []string{},
}))
+ r.Use(func(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ ctx := context.WithValue(r.Context(), "config", cfg)
+ next.ServeHTTP(w, r.WithContext(ctx))
+ })
+ })
return r
}