ADD: added initial page with login
This commit is contained in:
40
backend/cmd/server/main.go
Normal file
40
backend/cmd/server/main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user