-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (44 loc) · 1.34 KB
/
main.go
File metadata and controls
55 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"log"
"runrun/config"
"runrun/internal"
"runrun/internal/scheduler"
"runrun/routes"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
// Load application configuration from resource/application.yaml
if err := config.Init(); err != nil {
log.Fatalf("FATAL: Failed to initialize configuration: %v", err)
}
// Initialize Database
internal.InitDB()
// Initialize and start scheduler
sched := scheduler.NewScheduler()
sched.Start()
// Initialize Gin router
r := gin.Default()
// Configure CORS middleware
r.Use(cors.New(cors.Config{
AllowOrigins: []string{
"http://localhost:3000", // 本地开发
"https://runrun.1e27.net", // 你的Vercel域名
"https://*.vercel.app", // 所有Vercel预览域名
},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
// Initialize API routes
routes.InitApiRouter(r)
// Get port from config, with a fallback to 23450
port := config.GetString("server.port", "23450")
log.Printf("Server starting on port %s", port)
// Start the server
if err := r.Run(":" + port); err != nil {
log.Fatalf("FATAL: Failed to start server: %v", err)
}
}