diff --git a/Dockerfile b/Dockerfile index 2789a82..dec62ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,12 +43,13 @@ RUN chown -R appuser:appuser /root/ # 切换到非root用户 USER appuser -# 暴露端口 +# 暴露端口(Render 会通过 PORT 环境变量指定) EXPOSE 8002 +EXPOSE 10000 -# 健康检查 +# 健康检查(使用环境变量 PORT) HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD node -e "require('http').get('http://localhost:8002/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))" || exit 1 + CMD node -e "const port = process.env.PORT || 8002; require('http').get('http://localhost:' + port + '/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))" || exit 1 # 启动应用 CMD ["./cursor2api-go"] \ No newline at end of file diff --git a/main.go b/main.go index cae2caf..2c76140 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func main() { // 禁用 Gin 的调试信息输出 gin.DisableConsoleColor() - + // 创建路由器(使用 gin.New() 而不是 gin.Default() 以避免默认日志) router := gin.New() @@ -57,7 +57,7 @@ func main() { // 创建HTTP服务器 server := &http.Server{ - Addr: fmt.Sprintf(":%d", cfg.Port), + Addr: fmt.Sprintf("0.0.0.0:%d", cfg.Port), Handler: router, } @@ -122,10 +122,14 @@ func printStartupBanner(cfg *config.Config) { ` fmt.Println(banner) - fmt.Printf("🚀 服务地址: http://localhost:%d\n", cfg.Port) - fmt.Printf("📚 API 文档: http://localhost:%d/\n", cfg.Port) - fmt.Printf("💊 健康检查: http://localhost:%d/health\n", cfg.Port) - fmt.Printf("🔑 API 密钥: %s\n", maskAPIKey(cfg.APIKey)) + host := os.Getenv("RENDER_EXTERNAL_URL") + if host == "" { + host = fmt.Sprintf("http://localhost:%d", cfg.Port) + } + fmt.Printf("🚀 服务地址: %s\n", host) + fmt.Printf("📚 API 文档: %s/\n", host) + fmt.Printf("💊 健康检查: %s/health\n", host) + fmt.Printf("🔑 API 密钥: %s\n", cfg.APIKey) modelList := cfg.GetModels() fmt.Printf("\n🤖 支持模型 (%d 个):\n", len(modelList)) diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..8dab4b6 --- /dev/null +++ b/render.yaml @@ -0,0 +1,27 @@ +services: + - type: web + name: cursor2api-go + env: docker + plan: free + healthCheckPath: /health + envVars: + - key: PORT + value: 10000 + - key: DEBUG + value: false + - key: API_KEY + generateValue: true + - key: MODELS + value: gpt-5.1,gpt-5,gpt-5-codex,gpt-5-mini,gpt-5-nano,gpt-4.1,gpt-4o,claude-3.5-sonnet,claude-3.5-haiku,claude-3.7-sonnet,claude-4-sonnet,claude-4.5-sonnet,claude-4-opus,claude-4.1-opus,gemini-2.5-pro,gemini-2.5-flash,gemini-3.0-pro,o3,o4-mini,deepseek-r1,deepseek-v3.1,kimi-k2-instruct,grok-3 + - key: TIMEOUT + value: 60 + - key: MAX_INPUT_LENGTH + value: 200000 + - key: USER_AGENT + value: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 + - key: UNMASKED_VENDOR_WEBGL + value: Google Inc. (Intel) + - key: UNMASKED_RENDERER_WEBGL + value: ANGLE (Intel, Intel(R) UHD Graphics 620 Direct3D11 vs_5_0 ps_5_0, D3D11) + - key: SCRIPT_URL + value: https://cursor.com/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/a-4-a/c.js?i=0^&v=3^&h=cursor.com