Skip to content

Commit 7527ac9

Browse files
committed
feat: enabled cors for react:3000 app
1 parent c473ae0 commit 7527ac9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module aws-client-monitor
33
go 1.23.1
44

55
require (
6+
github.com/gin-contrib/cors v1.7.2
67
github.com/gin-gonic/contrib v0.0.0-20240508051311-c1c6bf0061b0
78
github.com/gin-gonic/gin v1.10.0
89
github.com/goccy/go-json v0.10.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1414
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1515
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
1616
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
17+
github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw=
18+
github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E=
1719
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
1820
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
1921
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=

internal/router/router.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package router
33
import (
44
"aws-client-monitor/docs"
55
"aws-client-monitor/internal/handler"
6+
"github.com/gin-contrib/cors"
7+
//"github.com/gin-gonic/contrib/cors"
68
"github.com/gin-gonic/contrib/static"
79
"github.com/gin-gonic/gin"
810
swaggerfiles "github.com/swaggo/files"
@@ -11,6 +13,14 @@ import (
1113

1214
func CreateRouter(router *gin.Engine) *gin.Engine {
1315
docs.SwaggerInfo.BasePath = "/api/v1"
16+
17+
// CORS middleware setup
18+
router.Use(cors.New(cors.Config{
19+
AllowOrigins: []string{"http://localhost:3000"},
20+
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
21+
AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
22+
AllowCredentials: true,
23+
}))
1424
v1 := router.Group("/api/v1")
1525
{
1626
v1.GET("/status", handler.StatusHandler)

0 commit comments

Comments
 (0)