41 lines
882 B
Go
41 lines
882 B
Go
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)
|
|
}
|