fix(gateway): added CORS middleware to allow all origins
Closes: #27 Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
_ "crypto/md5"
|
||||
_ "gateway-softweng/docs"
|
||||
paho "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
||||
"github.com/influxdata/influxdb-client-go/v2/api"
|
||||
@@ -78,6 +79,13 @@ func (gh *Gateway) createRestGateway() {
|
||||
// Create a new Gin router
|
||||
gh.rest = gin.Default()
|
||||
|
||||
// Configure CORS middleware to allow all origins
|
||||
config := cors.DefaultConfig()
|
||||
config.AllowAllOrigins = true
|
||||
config.AllowMethods = []string{"GET", "POST"}
|
||||
config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization"}
|
||||
gh.rest.Use(cors.New(config))
|
||||
|
||||
gh.rest.GET("/ping", pingHandler)
|
||||
|
||||
// Swagger documentation route
|
||||
|
||||
Reference in New Issue
Block a user