Configure CORS to use authentication
This commit is contained in:
11
main.go
11
main.go
@@ -24,7 +24,7 @@ func setup(config *config.Config) *gin.Engine {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(cors.Default()) // All origins allowed by default
|
r.Use(cors.New(configureCors())) // All origins allowed by default
|
||||||
r.Use(middleware.Auth())
|
r.Use(middleware.Auth())
|
||||||
r.GET("/books", func(c *gin.Context) {
|
r.GET("/books", func(c *gin.Context) {
|
||||||
api.GetBooksHanderl(c, db)
|
api.GetBooksHanderl(c, db)
|
||||||
@@ -40,3 +40,12 @@ func setup(config *config.Config) *gin.Engine {
|
|||||||
})
|
})
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configureCors() cors.Config {
|
||||||
|
config := cors.DefaultConfig()
|
||||||
|
config.AllowOrigins = []string{"http://localhost:5173"}
|
||||||
|
config.AllowPrivateNetwork = true
|
||||||
|
config.AllowCredentials = true
|
||||||
|
config.AllowHeaders = []string{"Authorization", "Content-Type"}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user