about summary refs log tree commit diff stats
path: root/internal/server
diff options
context:
space:
mode:
authorAlan Pearce2025-01-26 12:21:26 +0100
committerAlan Pearce2025-01-26 13:38:16 +0100
commit11457c6fdb101df1078b2a438486245263d7a292 (patch)
treead19707bfc46cfb0414296a3c9061c227c431400 /internal/server
parent7d9e98a0996eca0372e38cee4b8826d84a9ace2b (diff)
downloadwebsite-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.go12
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,