@@ -4,33 +4,34 @@ import (
44 "net/http"
55
66 "github.com/gin-contrib/cors"
7+ "github.com/gin-contrib/static"
78 "github.com/gin-gonic/gin"
89)
910
1011func (s * Server ) RegisterRouter () http.Handler {
1112 router := gin .Default ()
1213
1314 router .Use (cors .New (cors.Config {
14- AllowOrigins : []string {"http://localhost:5173 " }, // Add your frontend URL
15+ AllowOrigins : []string {"http://localhost:4000" , "https://trakrlog.com" , "https://www.trakrlog.com " }, // Add your frontend URL
1516 AllowMethods : []string {"GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" , "PATCH" },
1617 AllowHeaders : []string {"Accept" , "Authorization" , "Content-Type" },
1718 AllowCredentials : true , // Enable cookies/auth
1819 }))
1920
20- router .GET ("/" , s .HelloWorldHandler )
21+ // Serve static files from the React app build directory
22+ router .Use (static .Serve ("/" , static .LocalFile ("frontend/dist" , true )))
2123
22- router .GET ("/health" , s .healthHandler )
24+ // Serve React app for client-side routes (SPA fallback) - only for non-dashboard routes
25+ router .NoRoute (func (c * gin.Context ) {
26+ c .File ("frontend/dist/index.html" )
27+ })
2328
2429 return router
2530}
2631
27- func (s * Server ) HelloWorldHandler (c * gin.Context ) {
28- resp := make (map [string ]string )
29- resp ["message" ] = "Hello World"
32+ // func (s *Server) HelloWorldHandler(c *gin.Context) {
33+ // resp := make(map[string]string)
34+ // resp["message"] = "Hello World"
3035
31- c .JSON (http .StatusOK , resp )
32- }
33-
34- func (s * Server ) healthHandler (c * gin.Context ) {
35- c .JSON (http .StatusOK , s .db .Health ())
36- }
36+ // c.JSON(http.StatusOK, resp)
37+ // }
0 commit comments