avoid explicit fs.FS wrapping
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user