添加 /antigravity/v1/* 和 /antigravity/v1beta/* 路由: - 通过 ForcePlatform 中间件强制使用 antigravity 平台 - 跳过混合调度逻辑,仅调度 antigravity 账户 - 支持按分组优先查找,找不到时回退查询全部 antigravity 账户 修复 context key 类型不匹配问题: - middleware 和 service 统一使用字符串常量 "ctx_force_platform" - 解决 Go context.Value() 类型+值匹配导致的读取失败 其他改动: - 嵌入式前端中间件白名单添加 /antigravity/ 路径 - e2e 测试 Gemini 端点 URL 添加 endpointPrefix 支持
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
//go:build embed
|
|
|
|
package web
|
|
|
|
import (
|
|
"embed"
|
|
"io"
|
|
"io/fs"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
//go:embed all:dist
|
|
var frontendFS embed.FS
|
|
|
|
func ServeEmbeddedFrontend() gin.HandlerFunc {
|
|
distFS, err := fs.Sub(frontendFS, "dist")
|
|
if err != nil {
|
|
panic("failed to get dist subdirectory: " + err.Error())
|
|
}
|
|
fileServer := http.FileServer(http.FS(distFS))
|
|
|
|
return func(c *gin.Context) {
|
|
path := c.Request.URL.Path
|
|
|
|
if strings.HasPrefix(path, "/api/") ||
|
|
strings.HasPrefix(path, "/v1/") ||
|
|
strings.HasPrefix(path, "/v1beta/") ||
|
|
strings.HasPrefix(path, "/antigravity/") ||
|
|
strings.HasPrefix(path, "/setup/") ||
|
|
path == "/health" ||
|
|
path == "/responses" {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
cleanPath := strings.TrimPrefix(path, "/")
|
|
if cleanPath == "" {
|
|
cleanPath = "index.html"
|
|
}
|
|
|
|
if file, err := distFS.Open(cleanPath); err == nil {
|
|
_ = file.Close()
|
|
fileServer.ServeHTTP(c.Writer, c.Request)
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
serveIndexHTML(c, distFS)
|
|
}
|
|
}
|
|
|
|
func serveIndexHTML(c *gin.Context, fsys fs.FS) {
|
|
file, err := fsys.Open("index.html")
|
|
if err != nil {
|
|
c.String(http.StatusNotFound, "Frontend not found")
|
|
c.Abort()
|
|
return
|
|
}
|
|
defer func() { _ = file.Close() }()
|
|
|
|
content, err := io.ReadAll(file)
|
|
if err != nil {
|
|
c.String(http.StatusInternalServerError, "Failed to read index.html")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
c.Data(http.StatusOK, "text/html; charset=utf-8", content)
|
|
c.Abort()
|
|
}
|
|
|
|
func HasEmbeddedFrontend() bool {
|
|
_, err := frontendFS.ReadFile("dist/index.html")
|
|
return err == nil
|
|
}
|