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