diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 18:36:06 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 18:36:06 +0200 |
| commit | 49766901293631aeabfc96e8d80aba305f420630 (patch) | |
| tree | 56ada5226ac5d47a8277de00022190ab946490a1 /backend/router.go | |
| parent | 1168ac60d3a22c0d354f291fd657ad302df6ec05 (diff) | |
feat(backend): config to set domain
Diffstat (limited to 'backend/router.go')
| -rw-r--r-- | backend/router.go | 9 |
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 } |
