summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-09-06 01:24:35 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-09-06 01:32:42 -0700
commit81f20ab21a9cc5c7ce368adaa53e0ad88857db6b (patch)
tree9aebae814f1d94e501dd57b181e3194b9d53fe26
parentAdd projects link (diff)
downloadroseh.moe-81f20ab21a9cc5c7ce368adaa53e0ad88857db6b.tar.zst
Use ServeFileFS for static files
This allows listing the directories
-rw-r--r--roseh.moe.go20
1 files changed, 3 insertions, 17 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 55b3a72..32bcb6c 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -257,24 +257,10 @@ func buildStaticFileHashes() map[string]string {
}
func serveStaticFile(w http.ResponseWriter, r *http.Request, path string) {
- f, err := staticFiles.Open(path)
- if err != nil {
- notFound(w, r)
- return
- }
- defer f.Close()
- stat, err := f.Stat()
- if err != nil {
- log.Printf("Warning: stat static file: %s", err)
- http.Error(w, "internal error", http.StatusInternalServerError)
- return
- }
- if stat.IsDir() {
- notFound(w, r)
- return
+ if eTag, ok := staticFileHashes[path]; ok {
+ w.Header().Set("ETag", eTag)
}
- w.Header().Set("ETag", staticFileHashes[path])
- http.ServeContent(w, r, path, time.Time{}, f.(io.ReadSeeker))
+ http.ServeFileFS(w, r, staticFiles, path)
}
func static(w http.ResponseWriter, r *http.Request) {