* feat: 支持返回登录二维码与 Docker 部署 * feat: 完善扫码登录功能 * fix: 修复当存在已经登录的情况,上层还会启动 goroutine的问题,并把 mcp 的返回增加为图片格式
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// setupRoutes 设置路由配置
|
|
func setupRoutes(appServer *AppServer) *gin.Engine {
|
|
// 设置 Gin 模式
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
router := gin.New()
|
|
router.Use(gin.Logger())
|
|
router.Use(gin.Recovery())
|
|
|
|
// 添加中间件
|
|
router.Use(errorHandlingMiddleware())
|
|
router.Use(corsMiddleware())
|
|
|
|
// 健康检查
|
|
router.GET("/health", healthHandler)
|
|
|
|
// MCP 端点 - 使用 Streamable HTTP 协议
|
|
mcpHandler := appServer.StreamableHTTPHandler()
|
|
router.Any("/mcp", gin.WrapH(mcpHandler))
|
|
router.Any("/mcp/*path", gin.WrapH(mcpHandler))
|
|
|
|
// API 路由组
|
|
api := router.Group("/api/v1")
|
|
{
|
|
api.GET("/login/status", appServer.checkLoginStatusHandler)
|
|
api.GET("/login/qrcode", appServer.getLoginQrcodeHandler)
|
|
api.POST("/publish", appServer.publishHandler)
|
|
api.GET("/feeds/list", appServer.listFeedsHandler)
|
|
api.GET("/feeds/search", appServer.searchFeedsHandler)
|
|
api.POST("/feeds/detail", appServer.getFeedDetailHandler)
|
|
api.POST("/user/profile", appServer.userProfileHandler)
|
|
api.POST("/feeds/comment", appServer.postCommentHandler)
|
|
}
|
|
|
|
return router
|
|
}
|