ADD: added initial page with login

This commit is contained in:
hwinkel
2025-05-20 22:58:31 +02:00
parent 214ab55ad2
commit a330291456
25 changed files with 1064 additions and 35 deletions

View File

@@ -0,0 +1,40 @@
package main
import (
"os"
"volleyball/internal/auth"
"volleyball/internal/tournament"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
// CORS
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Authorization", "Content-Type"},
AllowCredentials: true,
}))
// Public
r.POST("/api/login", auth.LoginHandler)
r.GET("/api/tournaments", tournament.ListTournaments)
// Protected API
api := r.Group("/api")
api.Use(auth.AuthMiddleware())
api.GET("/tournaments/:id", tournament.GetTournament)
api.POST("/tournaments/:id/join", tournament.JoinTournament)
api.PUT("/tournaments/:id", tournament.UpdateTournament)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
r.Run(":" + port)
}