Skip to content

Commit 220d7ff

Browse files
committed
use gin-contrib/cors
1 parent 404511b commit 220d7ff

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

go.work.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
66
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
77
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
88
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
9-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
109
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
1110
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
1211
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
1312
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
13+
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
1414
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

node-registrar/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/threefoldtech/tfgrid4-sdk-go/node-registrar
33
go 1.21.0
44

55
require (
6+
github.com/gin-contrib/cors v1.7.3
67
github.com/gin-gonic/gin v1.10.0
78
github.com/lib/pq v1.10.9
89
github.com/pkg/errors v0.9.1

node-registrar/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ github.com/ethereum/go-ethereum v1.10.20 h1:75IW830ClSS40yrQC1ZCMZCt5I+zU16oqId2
3131
github.com/ethereum/go-ethereum v1.10.20/go.mod h1:LWUN82TCHGpxB3En5HVmLLzPD7YSrEUFmFfN1nKkVN0=
3232
github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA=
3333
github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU=
34+
github.com/gin-contrib/cors v1.7.3 h1:hV+a5xp8hwJoTw7OY+a70FsL8JkVVFTXw9EcfrYUdns=
35+
github.com/gin-contrib/cors v1.7.3/go.mod h1:M3bcKZhxzsvI+rlRSkkxHyljJt1ESd93COUvemZ79j4=
3436
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
3537
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
3638
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=

node-registrar/pkg/server/routes.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
package server
22

33
import (
4+
"time"
5+
6+
"github.com/gin-contrib/cors"
47
_ "github.com/threefoldtech/tfgrid4-sdk-go/node-registrar/docs"
58

69
swaggerFiles "github.com/swaggo/files"
710
ginSwagger "github.com/swaggo/gin-swagger"
811
)
912

1013
func (s *Server) SetupRoutes() {
14+
s.router.Use(cors.New(cors.Config{
15+
AllowOrigins: []string{"*"},
16+
AllowMethods: []string{"POST", "OPTIONS", "GET", "PUT", "DELETE"},
17+
AllowHeaders: []string{"*"},
18+
ExposeHeaders: []string{"*"},
19+
AllowCredentials: true,
20+
MaxAge: 12 * time.Hour,
21+
}))
22+
1123
s.router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
1224
v1 := s.router.Group("v1")
1325

14-
v1.Use(corsMiddleware())
15-
1626
// farms routes
1727
farmRoutes := v1.Group("farms")
1828
farmRoutes.GET("/", s.listFarmsHandler)

0 commit comments

Comments
 (0)