ADD: added initial page with login
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"volleyball/internal/database"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize the database connection
|
||||
var db = database.New("localhost", 5432, "user", "password", "dbname")
|
||||
db.Connect()
|
||||
|
||||
// Initialize the server
|
||||
// server := server.New(db)
|
||||
// server.Start()
|
||||
|
||||
// Initialize the router
|
||||
// router := router.New()
|
||||
// router.Start()
|
||||
// Initialize the logger
|
||||
// logger := logger.New()
|
||||
// logger.Start()
|
||||
// Initialize the config
|
||||
// config := config.New()
|
||||
|
||||
fmt.Println("Hello, World!")
|
||||
}
|
||||
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