diff --git a/http.go b/http.go index efc25a9..0382b0b 100644 --- a/http.go +++ b/http.go @@ -233,9 +233,9 @@ func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) s } if h.registerCORS { - h.opts.Logger.Infof(h.opts.Context, "register cors handler for http.MethodOptions %s /%s", hn, hn) - if err := hdlr.handlers.Insert([]string{http.MethodOptions}, "/"+hn, pth); err != nil { - h.opts.Logger.Errorf(h.opts.Context, "cant add rpc handler for http.MethodOptions %s /%s", hn, hn) + h.opts.Logger.Infof(h.opts.Context, "register cors handler for http.MethodOptions %s", md["Path"]) + if err := hdlr.handlers.Insert([]string{http.MethodOptions}, md["Path"], pth); err != nil { + h.opts.Logger.Errorf(h.opts.Context, "cant add handler for %s %s", md["Method"], md["Path"]) } } @@ -244,6 +244,13 @@ func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) s if err := hdlr.handlers.Insert([]string{http.MethodPost}, "/"+hn, pth); err != nil { h.opts.Logger.Errorf(h.opts.Context, "cant add rpc handler for http.MethodPost %s /%s", hn, hn) } + + if h.registerCORS { + h.opts.Logger.Infof(h.opts.Context, "register cors handler for http.MethodOptions %s /%s", hn, hn) + if err := hdlr.handlers.Insert([]string{http.MethodOptions}, "/"+hn, pth); err != nil { + h.opts.Logger.Errorf(h.opts.Context, "cant add rpc handler for http.MethodOptions %s /%s", hn, hn) + } + } } }