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"
"errors"
"io"
"io/fs"
"log/slog"
"net/http"
"os"
@@ -814,8 +815,15 @@ func apisBinds(vm *goja.Runtime) {
obj := vm.NewObject()
vm.Set("$apis", obj)
obj.Set("static", func(dir string, indexFallback bool) func(*core.RequestEvent) error {
return apis.Static(os.DirFS(dir), indexFallback)
obj.Set("static", func(dirOrFS any, indexFallback bool) func(*core.RequestEvent) error {
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