Implement api/server/cors (#1294)

This commit is contained in:
ben-toogood
2020-03-04 11:40:53 +00:00
committed by GitHub
parent 6a9001bdb1
commit 6d803d9e45
3 changed files with 58 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/gorilla/handlers"
"github.com/micro/go-micro/v2/api/server"
"github.com/micro/go-micro/v2/api/server/cors"
log "github.com/micro/go-micro/v2/logger"
)
@@ -45,7 +46,13 @@ func (s *httpServer) Init(opts ...server.Option) error {
}
func (s *httpServer) Handle(path string, handler http.Handler) {
s.mux.Handle(path, handlers.CombinedLoggingHandler(os.Stdout, handler))
h := handlers.CombinedLoggingHandler(os.Stdout, handler)
if s.opts.EnableCORS {
h = cors.CombinedCORSHandler(h)
}
s.mux.Handle(path, h)
}
func (s *httpServer) Start() error {