From 2cf0160aab224759eb5ce31e3cf8b47aeda9e899 Mon Sep 17 00:00:00 2001 From: Lenny Goodell Date: Thu, 21 Oct 2021 16:07:16 -0700 Subject: [PATCH] feat: Add CORS support (#983) Added CORS support enabled in go-mod-bootstrap closes #982 Signed-off-by: Leonard Goodell --- go.mod | 2 +- go.sum | 5 ++--- internal/webserver/server.go | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 635e3505c..c1b478dc0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690 github.com/diegoholiveira/jsonlogic v1.0.1-0.20200220175622-ab7989be08b9 github.com/eclipse/paho.mqtt.golang v1.3.5 - github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.1-dev.13 + github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.1-dev.14 github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.1-dev.23 github.com/edgexfoundry/go-mod-messaging/v2 v2.0.2-dev.6 github.com/edgexfoundry/go-mod-registry/v2 v2.0.1-dev.8 diff --git a/go.sum b/go.sum index bfd063f06..3c0b35625 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.3.5 h1:sWtmgNxYM9P2sP+xEItMozsR3w0cqZFlqnNN1bdl41Y= github.com/eclipse/paho.mqtt.golang v1.3.5/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc= -github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.1-dev.13 h1:LvbGywemQcG2xgZi6MaK63b5G+Vt1SF3tP7Lly6DdVs= -github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.1-dev.13/go.mod h1:FUTBZgP4hMyJOetw3WkM6trUs2SG3AceO3NAZhZyG9M= +github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.1-dev.14 h1:vTV7AM2HnP5HiIPzED7Cd1PAXsKpWjj6m/nP39L4fM4= +github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.1-dev.14/go.mod h1:84xs+nDgmAu8X2qTWsj9GTkgcIQDzS+O/O6RjvFE38M= github.com/edgexfoundry/go-mod-configuration/v2 v2.0.1-dev.5 h1:icE1aVlX7I3SJ0qPqZJchCr2JLe2TMRZlUMIM2qoivo= github.com/edgexfoundry/go-mod-configuration/v2 v2.0.1-dev.5/go.mod h1:MvHit0MxBXN4bC8LL0NZRsw72ByRE1XwtVLQP9C+2vg= github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0/go.mod h1:pfXURRetgIto0GR0sCjDrfa71hqJ1wxmQWi/mOzWfWU= @@ -148,7 +148,6 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= diff --git a/internal/webserver/server.go b/internal/webserver/server.go index 5f83b8e0e..6fa7c2ce3 100644 --- a/internal/webserver/server.go +++ b/internal/webserver/server.go @@ -21,6 +21,8 @@ import ( "net/http" "time" + "github.com/edgexfoundry/go-mod-bootstrap/v2/bootstrap/handlers" + "github.com/edgexfoundry/app-functions-sdk-go/v2/internal" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/bootstrap/container" sdkCommon "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/common" @@ -83,6 +85,8 @@ func (webserver *WebServer) ConfigureStandardRoutes() { router.HandleFunc(common.ApiConfigRoute, controller.Config).Methods(http.MethodGet) router.HandleFunc(internal.ApiAddSecretRoute, controller.AddSecret).Methods(http.MethodPost) + router.Use(handlers.ProcessCORS(webserver.config.Service.CORSConfiguration)) + /// Trigger is not considered a standard route. Trigger route (when configured) is setup by the HTTP Trigger // in internal/trigger/http/rest.go }