This commit is contained in:
cdle
2023-06-03 17:30:48 +08:00
parent 62238bad8e
commit bdc884fbe4
7 changed files with 163 additions and 50 deletions
+31
View File
@@ -13,6 +13,7 @@ import (
"github.com/cdle/sillyplus/core/logs"
"github.com/cdle/sillyplus/core/storage"
"github.com/cdle/sillyplus/utils"
"github.com/dop251/goja"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
@@ -88,6 +89,36 @@ func init() {
c: c,
}
for _, function := range Functions {
if function.Http != nil {
path := function.Http.Path
method := function.Http.Method
if c.Request.URL.Path == path && c.Request.Method == method {
req.handled = true
function.Handle(&Faker{
Type: "*",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("req", req)
vm.Set("response", res)
vm.Set("request", req)
})
}
}
}
if req.handled {
if res.isRedirect {
return
}
if res.isJson {
c.Header("Content-Type", "application/json")
}
c.String(res.status, res.content)
return
}
httpListensAny.Range(func(_, value any) bool {
web := value.(*HttpListen)
if web.Closed {