- Android: Added INTERNET permission and enabled cleartext traffic in AndroidManifest.xml. - Web: Implemented and registered CORSMiddleware in backend to allow cross-origin requests. - Flutter: Updated SettingsProvider to use 10.0.2.2 as default for Android Emulator for easier local testing.
38 lines
866 B
Go
38 lines
866 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// SetupRouter configures the Gin router and defines API endpoints
|
|
func SetupRouter() *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)
|
|
|
|
// 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
|
|
}
|