summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-10-16 10:11:15 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-10-16 10:23:05 -0700
commit9e2f049e11d6dd735976018a5156ad9df5552f38 (patch)
tree7e793cbf6e0768bc3a2b93ebcf964ef8daa61b2f /roseh.moe.go
parentRedirect HTTP to HTTPS (diff)
downloadroseh.moe-9e2f049e11d6dd735976018a5156ad9df5552f38.tar.zst
Serve files from a certain directory on root
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 6ad701f..063a08a 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -321,6 +321,31 @@ func favicon(w http.ResponseWriter, r *http.Request) {
serveStaticFile(w, r, "static/favicon.ico")
}
+func sharedFileHandler(w http.ResponseWriter, r *http.Request) {
+ fp, err := filepath.Localize(path.Clean(strings.TrimPrefix(r.URL.Path, "/")))
+ if err != nil {
+ notFound(w, r)
+ return
+ }
+ f, err := os.OpenInRoot(filepath.Join(*nezuko, "www"), fp)
+ if err != nil {
+ notFound(w, r)
+ return
+ }
+ defer f.Close()
+ stat, err := f.Stat()
+ if err != nil {
+ log.Printf("Warning: sharedFileHandler: %s", err)
+ notFound(w, r)
+ return
+ }
+ if stat.IsDir() {
+ notFound(w, r)
+ return
+ }
+ http.ServeContent(w, r, fp, stat.ModTime(), f)
+}
+
func qrHandler(w http.ResponseWriter, r *http.Request) {
sig, err := base64.RawURLEncoding.DecodeString(r.FormValue("s"))
if err != nil {
@@ -1218,7 +1243,7 @@ func main() {
apiMux := http.NewServeMux()
apiMux.HandleFunc("PUT /api/wormhole/{name}", wormholeAPIUpload)
mux.Handle("/api/", apiMux)
- mux.Handle("/", &timeoutHandler{h: http.HandlerFunc(notFound), timeout: 5 * time.Minute})
+ mux.Handle("/", &timeoutHandler{h: http.HandlerFunc(sharedFileHandler), timeout: 5 * time.Minute})
serverMux := http.NewServeMux()
serverMux.Handle(selfURL.Hostname()+"/", http.NewCrossOriginProtection().Handler(&gzipHandler{mux}))
jellyfinURL, err := url.Parse("http://127.0.0.1:8096")