remove reqObj from runHonoMiddleware func parameters

This commit is contained in:
syumai 2024-02-11 19:51:22 +09:00
parent 8cf026a01b
commit d9dc0f1480

View File

@ -32,17 +32,16 @@ func ChainMiddlewares(middlewares ...Middleware) Middleware {
func init() {
runHonoMiddlewareCallback := js.FuncOf(func(_ js.Value, args []js.Value) any {
if len(args) > 2 {
if len(args) > 1 {
panic(fmt.Errorf("too many args given to handleRequest: %d", len(args)))
}
reqObj := args[0]
nextFnObj := args[1]
nextFnObj := args[0]
var cb js.Func
cb = js.FuncOf(func(_ js.Value, pArgs []js.Value) any {
defer cb.Release()
resolve := pArgs[0]
go func() {
err := runHonoMiddleware(reqObj, nextFnObj)
err := runHonoMiddleware(nextFnObj)
if err != nil {
panic(err)
}
@ -55,11 +54,11 @@ func init() {
jsutil.Binding.Set("runHonoMiddleware", runHonoMiddlewareCallback)
}
func runHonoMiddleware(reqObj, nextFnObj js.Value) error {
func runHonoMiddleware(nextFnObj js.Value) error {
if middleware == nil {
return fmt.Errorf("ServeMiddleware must be called before runHonoMiddleware.")
}
c := newContext(reqObj)
c := newContext(jsutil.RuntimeContext)
next := func() {
jsutil.AwaitPromise(nextFnObj.Invoke())
}