From 11457c6fdb101df1078b2a438486245263d7a292 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 26 Jan 2025 12:21:26 +0100 Subject: refactor mux filemap into files.Reader --- internal/server/server.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'internal/server') diff --git a/internal/server/server.go b/internal/server/server.go index b5526a0..e4ff63b 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -16,6 +16,7 @@ import ( "go.alanpearce.eu/website/internal/builder" cfg "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/website/internal/storage/files" "go.alanpearce.eu/website/internal/vcs" "go.alanpearce.eu/website/internal/website" "go.alanpearce.eu/x/log" @@ -174,7 +175,14 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) { } loggingMux := http.NewServeMux() - mux, err := website.NewMux(config, runtimeConfig.Root, log.Named("website")) + + log.Debug("registering content files", "root", runtimeConfig.Root) + reader, err := files.NewReader(runtimeConfig.Root, log.Named("files")) + if err != nil { + return nil, errors.WithMessage(err, "could not create file reader") + } + + mux, err := website.NewMux(config, reader, log.Named("website")) if err != nil { return nil, errors.WithMessage(err, "could not create website mux") } @@ -188,7 +196,7 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) { loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { switch { case slices.Contains(config.Domains, r.Host): - path, _ := website.CanonicalisePath(r.URL.Path) + path, _ := reader.CanonicalisePath(r.URL.Path) http.Redirect( w, r, -- cgit 1.4.1