From 49382c5d0348814e1d3d7ff4ec91317376fb8861 Mon Sep 17 00:00:00 2001 From: kyx236 Date: Fri, 30 Jan 2026 09:10:37 +0800 Subject: [PATCH] feat: Implement the initial backend HTTP API server with configuration, logging, S2A proxy, mail service management, and team owner database operations. --- backend/cmd/main.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 3535bc7..6375729 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -271,6 +271,8 @@ func handleS2AProxy(w http.ResponseWriter, r *http.Request) { targetURL += "?" + r.URL.RawQuery } + logger.Info(fmt.Sprintf("S2A Proxy: %s -> %s", r.URL.Path, targetURL), "", "proxy") + // 创建代理请求 proxyReq, err := http.NewRequest(r.Method, targetURL, r.Body) if err != nil { @@ -278,26 +280,31 @@ func handleS2AProxy(w http.ResponseWriter, r *http.Request) { return } - // 复制请求头 - for key, values := range r.Header { - for _, value := range values { - proxyReq.Header.Add(key, value) - } - } + // 设置认证头 - 尝试多种格式 + adminKey := config.Global.S2AAdminKey + logger.Info(fmt.Sprintf("Using admin key (len=%d, prefix=%s...)", len(adminKey), adminKey[:min(8, len(adminKey))]), "", "proxy") - // 设置认证头 - proxyReq.Header.Set("Authorization", "Bearer "+config.Global.S2AAdminKey) + proxyReq.Header.Set("Authorization", "Bearer "+adminKey) + proxyReq.Header.Set("X-API-Key", adminKey) + proxyReq.Header.Set("X-Admin-Key", adminKey) // 可能是这个 proxyReq.Header.Set("Content-Type", "application/json") + proxyReq.Header.Set("Accept", "application/json") // 发送请求 client := &http.Client{Timeout: 30 * time.Second} resp, err := client.Do(proxyReq) if err != nil { + logger.Error(fmt.Sprintf("S2A 请求失败: %v", err), "", "proxy") api.Error(w, http.StatusBadGateway, fmt.Sprintf("请求 S2A 失败: %v", err)) return } defer resp.Body.Close() + // 记录响应状态 + if resp.StatusCode != 200 { + logger.Warning(fmt.Sprintf("S2A 返回 %d", resp.StatusCode), "", "proxy") + } + // 复制响应头 for key, values := range resp.Header { for _, value := range values {