aboutsummaryrefslogtreecommitdiff
path: root/internal/fs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/fs/fs.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/fs/fs.go b/internal/fs/fs.go
new file mode 100644
index 0000000..7b2704b
--- /dev/null
+++ b/internal/fs/fs.go
@@ -0,0 +1,18 @@
+package fs
+
+import (
+ "net/http"
+ "strings"
+
+ "github.com/go-chi/chi"
+)
+
+func NewHandler(path string) http.HandlerFunc {
+ filesDir := http.Dir(path)
+ return func(w http.ResponseWriter, r *http.Request) {
+ rctx := chi.RouteContext(r.Context())
+ pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*")
+ fs := http.StripPrefix(pathPrefix, http.FileServer(filesDir))
+ fs.ServeHTTP(w, r)
+ }
+}