Skip to content

Commit

Permalink
Merge pull request #31 from observerly/feature/middleware/cross-origi…
Browse files Browse the repository at this point in the history
…n-resource-sharing

feat: Added GIN_MODE switch to the CORS origins whitelisting.
  • Loading branch information
michealroberts authored Jul 3, 2022
2 parents 4bea823 + ad28b32 commit f92bce5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
21 changes: 12 additions & 9 deletions coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ github.com/observerly/nocturnal/internal/router/setup.go:18.2,18.14 1 1
github.com/observerly/nocturnal/internal/router/setup.go:15.13,17.3 1 1
github.com/observerly/nocturnal/internal/router/setup.go:21.32,26.23 3 1
github.com/observerly/nocturnal/internal/router/setup.go:31.2,37.71 3 1
github.com/observerly/nocturnal/internal/router/setup.go:49.2,58.41 2 1
github.com/observerly/nocturnal/internal/router/setup.go:68.2,68.40 1 1
github.com/observerly/nocturnal/internal/router/setup.go:80.2,80.33 1 1
github.com/observerly/nocturnal/internal/router/setup.go:84.2,84.10 1 1
github.com/observerly/nocturnal/internal/router/setup.go:49.2,49.23 1 1
github.com/observerly/nocturnal/internal/router/setup.go:68.2,68.41 1 1
github.com/observerly/nocturnal/internal/router/setup.go:78.2,78.40 1 1
github.com/observerly/nocturnal/internal/router/setup.go:90.2,90.33 1 1
github.com/observerly/nocturnal/internal/router/setup.go:94.2,94.10 1 1
github.com/observerly/nocturnal/internal/router/setup.go:26.23,28.3 1 1
github.com/observerly/nocturnal/internal/router/setup.go:37.71,38.40 1 0
github.com/observerly/nocturnal/internal/router/setup.go:46.3,46.52 1 0
github.com/observerly/nocturnal/internal/router/setup.go:38.40,45.4 1 0
github.com/observerly/nocturnal/internal/router/setup.go:58.41,65.3 1 1
github.com/observerly/nocturnal/internal/router/setup.go:68.40,77.3 1 1
github.com/observerly/nocturnal/internal/router/setup.go:80.33,82.3 1 1
github.com/observerly/nocturnal/pkg/twilight/twilight.go:13.34,74.2 14 1
github.com/observerly/nocturnal/internal/router/setup.go:49.23,52.3 2 0
github.com/observerly/nocturnal/internal/router/setup.go:52.8,66.3 2 1
github.com/observerly/nocturnal/internal/router/setup.go:68.41,75.3 1 1
github.com/observerly/nocturnal/internal/router/setup.go:78.40,87.3 1 1
github.com/observerly/nocturnal/internal/router/setup.go:90.33,92.3 1 1
github.com/observerly/nocturnal/pkg/moon/moon.go:14.30,60.22 16 1
github.com/observerly/nocturnal/pkg/moon/moon.go:66.2,66.21 1 1
github.com/observerly/nocturnal/pkg/moon/moon.go:72.2,77.4 1 1
github.com/observerly/nocturnal/pkg/moon/moon.go:60.22,62.3 1 0
github.com/observerly/nocturnal/pkg/moon/moon.go:62.8,64.3 1 1
github.com/observerly/nocturnal/pkg/moon/moon.go:66.21,68.3 1 0
github.com/observerly/nocturnal/pkg/moon/moon.go:68.8,70.3 1 1
github.com/observerly/nocturnal/pkg/transit/transit.go:14.33,92.2 25 3
github.com/observerly/nocturnal/pkg/twilight/twilight.go:13.34,74.2 14 1
github.com/observerly/nocturnal/pkg/sun/sun.go:14.29,56.2 13 1
github.com/observerly/nocturnal/pkg/transit/transit.go:14.33,92.2 25 3
26 changes: 18 additions & 8 deletions internal/router/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,24 @@ func SetupRouter() *gin.Engine {
c.AbortWithStatus(http.StatusInternalServerError)
}))

r.Use(cors.New(cors.Config{
AllowOrigins: []string{"https://observerly.com", "https://app.observerly.com"},
AllowMethods: []string{"GET", "OPTIONS"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 24 * time.Hour,
}))
if mode != "release" {
config := cors.Default()
r.Use(config)
} else {
config := cors.Config{
AllowOrigins: []string{
"https://observerly.com",
"https://app.observerly.com",
"http://localhost:3000",
},
AllowMethods: []string{"GET", "OPTIONS"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 24 * time.Hour,
}
r.Use(cors.New(config))
}

r.GET("/version", func(c *gin.Context) {
c.JSON(
Expand Down

0 comments on commit f92bce5

Please sign in to comment.