From 9c29d92d7f3d9c48a0e64738502c8a03bdb0e286 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 18 Mar 2024 15:45:43 +0300 Subject: [PATCH] fixup cors path handler Signed-off-by: Vasiliy Tolstov --- http.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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) + } + } } }