Files
xiaolajiaoyyds 6f71df4849 Initial open-source release
多平台账号批量注册系统,支持 OpenAI / Grok / Kiro / Gemini 平台的全自动注册。

Features:
- 用户名/密码注册登录(首个用户自动管理员)
- JWT 认证 + bcrypt 密码加密
- 积分系统与多用户管理
- HuggingFace Space 弹性 Worker 节点管理
- Cloudflare Worker 负载均衡
- 实时日志推送(SSE/WebSocket)
- 管理后台(用户管理、系统设置、代理池、卡池)

Tech Stack: Go 1.25 / Gin / GORM / PostgreSQL / Vue 3 / Vite / TailwindCSS
2026-03-22 03:44:42 +08:00

42 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package middleware
import (
"os"
"strings"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
// CORS 跨域中间件
// 生产环境通过 CORS_ORIGINS 环境变量配置允许的域名(逗号分隔)
// 开发模式(GIN_MODE != release)允许所有来源
func CORS() gin.HandlerFunc {
return cors.New(cors.Config{
AllowOriginFunc: func(origin string) bool {
// 开发模式允许所有来源
if os.Getenv("GIN_MODE") != "release" {
return true
}
// 生产环境:读取 CORS_ORIGINS 白名单
allowed := os.Getenv("CORS_ORIGINS")
if allowed == "" {
// 未配置则允许同源请求(Origin 为空时浏览器不发送 CORS preflight)
return origin == ""
}
for _, a := range strings.Split(allowed, ",") {
if strings.TrimSpace(a) == origin {
return true
}
}
return false
},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization", "X-Auth-Token"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}