feat: Implement the initial backend HTTP API server with configuration, logging, S2A proxy, mail service management, and team owner database operations.

This commit is contained in:
2026-01-30 09:10:37 +08:00
parent 6d236419b9
commit 49382c5d03

View File

@@ -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 {