Skip to content

Commit 96b51c2

Browse files
update cors
1 parent 3c2fa9f commit 96b51c2

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

internal/handlers/server.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
type Server struct {
25-
db *gorm.DB
25+
db *gorm.DB
2626
config *config.Config
2727
router *gin.Engine
2828
}
@@ -41,18 +41,18 @@ func (s *Server) setupRoutes() {
4141
s.router.Use(gin.Recovery())
4242

4343
s.router.Use(cors.New(cors.Config{
44-
AllowOrigins: []string{"http://localhost:3000", "https://forgotten.onrender.com"},
45-
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
46-
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
47-
ExposeHeaders: []string{"Content-Length"},
48-
AllowCredentials: true,
49-
MaxAge: 12 * time.Hour,
50-
}))
44+
AllowOrigins: []string{"http://localhost:3000", "https://forgotten.onrender.com"},
45+
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
46+
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
47+
ExposeHeaders: []string{"Content-Length"},
48+
AllowCredentials: true,
49+
MaxAge: 12 * time.Hour,
50+
}))
5151
s.router.Use(middleware.LoggingMiddleware())
5252
s.router.Use(middleware.MetricsMiddleware())
5353
_ = s.router.SetTrustedProxies(nil)
5454

55-
s.router.HEAD("/health", func(c *gin.Context) { c.Status(http.StatusOK) })
55+
s.router.HEAD("/health", func(c *gin.Context) { c.Status(http.StatusOK) })
5656

5757
var userRepo repository.UserRepository = repository.NewUserRepository(s.db)
5858
var clubRepo repository.ClubRepository = repository.NewClubRepository(s.db)
@@ -135,7 +135,7 @@ func (s *Server) setupRoutes() {
135135
protected.POST("/clubs/:id/join", clubHandler.JoinClub)
136136
protected.POST("/clubs/:id/leave", middleware.RequireClubMembership(clubRepo), clubHandler.LeaveClub)
137137
protected.POST("/clubs/:id/ratings", middleware.RequireClubMembership(clubRepo), clubHandler.RateClub)
138-
138+
139139
protected.GET("/clubs/:id/members", clubHandler.ListClubMembers)
140140
protected.PUT("/clubs/:id/members/:user_id", middleware.RequireClubMembershipWithRoles(clubRepo, "club_admin", "moderator"), clubHandler.UpdateClubMember)
141141
protected.GET("/clubs/:id/members/:user_id", clubHandler.GetClubMember)
@@ -178,18 +178,18 @@ func (s *Server) setupRoutes() {
178178

179179
protected.POST("/users/:id/reading/sync", middleware.AuthorizeSelf(), readingHandler.SyncUserStats)
180180
protected.POST("/users/:id/reading/start", middleware.AuthorizeSelf(), readingHandler.StartReading)
181-
protected.PATCH("/users/:id/reading/:bookID/progress", middleware.AuthorizeSelf(), readingHandler.UpdateProgress)
182-
protected.POST("/users/:id/reading/:bookID/complete", middleware.AuthorizeSelf(), readingHandler.CompleteReading)
183-
protected.GET("/users/:id/reading", middleware.AuthorizeSelf(), readingHandler.ListUserProgress)
184-
protected.GET("/users/:id/reading/history", readingHandler.UserReadingHistory)
185-
186-
protected.POST("/clubs/:id/reading/assign", middleware.RequireClubMembershipWithRoles(clubRepo, "admin", "moderator"), readingHandler.AssignBookToClub)
187-
protected.PATCH("/clubs/:id/reading/checkpoint", middleware.RequireClubMembershipWithRoles(clubRepo, "admin", "moderator"), readingHandler.UpdateClubCheckpoint)
188-
protected.POST("/clubs/:id/reading/complete", middleware.RequireClubMembershipWithRoles(clubRepo, "admin", "moderator"), readingHandler.CompleteClubAssignment)
189-
protected.GET("/clubs/:id/reading", readingHandler.ListClubAssignments)
181+
protected.PATCH("/users/:id/reading/:bookID/progress", middleware.AuthorizeSelf(), readingHandler.UpdateProgress)
182+
protected.POST("/users/:id/reading/:bookID/complete", middleware.AuthorizeSelf(), readingHandler.CompleteReading)
183+
protected.GET("/users/:id/reading", middleware.AuthorizeSelf(), readingHandler.ListUserProgress)
184+
protected.GET("/users/:id/reading/history", readingHandler.UserReadingHistory)
185+
186+
protected.POST("/clubs/:id/reading/assign", middleware.RequireClubMembershipWithRoles(clubRepo, "admin", "moderator"), readingHandler.AssignBookToClub)
187+
protected.PATCH("/clubs/:id/reading/checkpoint", middleware.RequireClubMembershipWithRoles(clubRepo, "admin", "moderator"), readingHandler.UpdateClubCheckpoint)
188+
protected.POST("/clubs/:id/reading/complete", middleware.RequireClubMembershipWithRoles(clubRepo, "admin", "moderator"), readingHandler.CompleteClubAssignment)
189+
protected.GET("/clubs/:id/reading", readingHandler.ListClubAssignments)
190190
}
191191
}
192192

193193
func (s *Server) Start(addr string) error {
194194
return s.router.Run(addr)
195-
}
195+
}

0 commit comments

Comments
 (0)