diff options
author | Alan Pearce | 2025-01-26 12:21:26 +0100 |
---|---|---|
committer | Alan Pearce | 2025-01-26 13:38:16 +0100 |
commit | 11457c6fdb101df1078b2a438486245263d7a292 (patch) | |
tree | ad19707bfc46cfb0414296a3c9061c227c431400 /internal/server | |
parent | 7d9e98a0996eca0372e38cee4b8826d84a9ace2b (diff) | |
download | website-11457c6fdb101df1078b2a438486245263d7a292.tar.lz website-11457c6fdb101df1078b2a438486245263d7a292.tar.zst website-11457c6fdb101df1078b2a438486245263d7a292.zip |
refactor mux filemap into files.Reader
Diffstat (limited to 'internal/server')
-rw-r--r-- | internal/server/server.go | 12 |
1 files changed, 10 insertions, 2 deletions
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, |