From 95a6bce0b1eb2b81c2d386e8e04caf41669763f0 Mon Sep 17 00:00:00 2001 From: qian Date: Sat, 8 Aug 2026 10:23:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E7=BB=99=E5=90=8E=E7=AB=AF=E4=B8=80=E4=B8=AA=E8=90=BD?= =?UTF-8?q?=E5=9C=B0=E9=A1=B5=E5=BC=95=E5=AF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/cmd/cmd.go | 16 +++ internal/handler/landing/landing.go | 19 ++++ internal/packed/landing.html | 150 ++++++++++++++++++++++++++++ internal/packed/packed.go | 3 + 4 files changed, 188 insertions(+) create mode 100644 internal/handler/landing/landing.go create mode 100644 internal/packed/landing.html diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 2522d61..e976bf7 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -33,6 +33,7 @@ import ( "github.com/qianfree/team-api/internal/utility/crypto" adminHandler "github.com/qianfree/team-api/internal/handler/admin" + "github.com/qianfree/team-api/internal/handler/landing" "github.com/qianfree/team-api/internal/handler/public" "github.com/qianfree/team-api/internal/handler/relay" setupHandler "github.com/qianfree/team-api/internal/handler/setup" @@ -261,6 +262,9 @@ var ( // Embedded frontend SPA serving registerFrontendRoutes(s) + // Landing page for backend root when frontend is not embedded + registerLandingPage(s) + // Migrate encryption key (legacy default → configured key) relayLogic.MigrateEncryptionKey(ctx) @@ -468,6 +472,18 @@ func registerRelayRoutes(server *ghttp.Server) { }) } +// registerLandingPage 在未内嵌前端(非 embedweb 构建)时,为后端根路径注册项目介绍页, +// 避免浏览器直接访问后端地址时显示 404。内嵌前端时根路径由租户 SPA 承接,此页不注册。 +func registerLandingPage(s *ghttp.Server) { + if web.Enabled { + return + } + s.Group("/", func(group *ghttp.RouterGroup) { + group.GET("/", landing.HandleLanding) + group.GET("/index.html", landing.HandleLanding) + }) +} + // registerFrontendRoutes serves embedded frontend SPA assets. // Admin console at /admin, tenant console at / (catch-all). // Existing API routes take priority over these wildcard routes. diff --git a/internal/handler/landing/landing.go b/internal/handler/landing/landing.go new file mode 100644 index 0000000..899e43b --- /dev/null +++ b/internal/handler/landing/landing.go @@ -0,0 +1,19 @@ +package landing + +import ( + "strings" + + "github.com/gogf/gf/v2/net/ghttp" + + "github.com/qianfree/team-api/internal/consts" + "github.com/qianfree/team-api/internal/packed" +) + +// HandleLanding serves the embedded landing page for the backend root path. +// 未内嵌前端(非 embedweb 构建)时访问后端根路径会命中默认 404,这里提供项目介绍页, +// 引导用户从管理后台 / 租户控制台进入,并展示版本号与常用接口入口。 +func HandleLanding(r *ghttp.Request) { + html := strings.Replace(string(packed.LandingHTML), "__VERSION__", consts.Version, 1) + r.Response.Header().Set("Content-Type", "text/html; charset=utf-8") + r.Response.Write([]byte(html)) +} diff --git a/internal/packed/landing.html b/internal/packed/landing.html new file mode 100644 index 0000000..d7f8662 --- /dev/null +++ b/internal/packed/landing.html @@ -0,0 +1,150 @@ + + + + + + Team-API · 企业级大模型 API 网关 + + + + + + + + + + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Team-API

+

企业级大模型 API 网关

+
+ + +

+ 统一接入 OpenAI / Claude / Gemini 等主流大模型,为多租户提供 API Key 管理与计费能力 +

+ + + + + +

+ 开发环境请通过 Vite 访问 + 管理后台 :4001 + · + 租户控制台 :4002 +

+ +

+ Team-API v__VERSION__ +

+
+
+ + + + diff --git a/internal/packed/packed.go b/internal/packed/packed.go index fdd3c30..bf31e4f 100644 --- a/internal/packed/packed.go +++ b/internal/packed/packed.go @@ -4,3 +4,6 @@ import _ "embed" //go:embed setup.html var SetupHTML []byte + +//go:embed landing.html +var LandingHTML []byte