This commit is contained in:
2026-04-18 14:38:37 +03:00
parent 3ee88f9343
commit 6c871cd9eb
21 changed files with 1736 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ package server
import (
"net/http"
"strings"
"time"
"github.com/gin-contrib/cors"
@@ -16,10 +17,21 @@ import (
func NewRouter(db *gorm.DB, cfg config.Config) *gin.Engine {
router := gin.Default()
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:5173", "http://127.0.0.1:5173", "http://localhost:8081", "http://127.0.0.1:8081", "https://social-rating.nekiiinkognito.ru/"},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowOriginFunc: func(origin string) bool {
switch {
case strings.HasPrefix(origin, "http://localhost:"):
return true
case strings.HasPrefix(origin, "http://127.0.0.1:"):
return true
case origin == "https://social-rating.nekiiinkognito.ru":
return true
default:
return false
}
},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
@@ -38,6 +50,10 @@ func NewRouter(db *gorm.DB, cfg config.Config) *gin.Engine {
protected := api.Group("/")
protected.Use(auth.Middleware(cfg.JWTSecret))
protected.GET("/auth/me", authHandler.Me)
protected.GET("/users", socialRatingHandler.ListUsers)
protected.GET("/users/:userId", socialRatingHandler.GetUser)
protected.GET("/users/:userId/social-rating/history", socialRatingHandler.GetUserHistory)
protected.GET("/social-rating/operations", socialRatingHandler.GetRecentOperations)
protected.POST("/social-rating/increase", socialRatingHandler.Increase)
protected.POST("/social-rating/decrease", socialRatingHandler.Decrease)