avoid explicit fs.FS wrapping

This commit is contained in:
Gani Georgiev
2026-04-02 08:06:11 +03:00
parent 64854ef08d
commit 3a893d15ad

View File

@@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"io/fs"
"log/slog" "log/slog"
"net/http" "net/http"
"os" "os"
@@ -814,8 +815,15 @@ func apisBinds(vm *goja.Runtime) {
obj := vm.NewObject() obj := vm.NewObject()
vm.Set("$apis", obj) vm.Set("$apis", obj)
obj.Set("static", func(dir string, indexFallback bool) func(*core.RequestEvent) error { obj.Set("static", func(dirOrFS any, indexFallback bool) func(*core.RequestEvent) error {
return apis.Static(os.DirFS(dir), indexFallback) switch v := dirOrFS.(type) {
case fs.FS:
return apis.Static(v, indexFallback)
case string:
return apis.Static(os.DirFS(v), indexFallback)
default:
panic("$apis.static expects the first argument to be either a plain string path or fs.FS value")
}
}) })
// middlewares // middlewares