fix(gateway): added CORS middleware to allow all origins

Closes: #27
Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
2025-05-06 10:36:01 +02:00
parent 9cf3387093
commit 2d92d5a93a
3 changed files with 52 additions and 40 deletions

View File

@@ -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