Files
Hightube/backend/internal/api/router.go
2026-04-01 11:30:52 +08:00

41 lines
979 B
Go

package api
import (
"github.com/gin-gonic/gin"
"hightube/internal/stream"
)
// SetupRouter configures the Gin router and defines API endpoints
func SetupRouter(streamServer *stream.RTMPServer) *gin.Engine {
// 设置为发布模式,消除 "[WARNING] Running in debug mode" 警告
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
// Use CORS middleware to allow web access
r.Use(CORSMiddleware())
// 清除代理信任警告 "[WARNING] You trusted all proxies"
r.SetTrustedProxies(nil)
// Public routes
r.POST("/api/register", Register)
r.POST("/api/login", Login)
r.GET("/api/rooms/active", GetActiveRooms)
r.GET("/live/:room_id", streamServer.HandleHTTPFLV)
// WebSocket endpoint for live chat
r.GET("/api/ws/room/:room_id", WSHandler)
// Protected routes (require JWT)
authGroup := r.Group("/api")
authGroup.Use(AuthMiddleware())
{
authGroup.GET("/room/my", GetMyRoom)
authGroup.POST("/user/change-password", ChangePassword)
}
return r
}