36 lines
793 B
Go
36 lines
793 B
Go
package main
|
|
|
|
import (
|
|
"bbs-backend/api/router"
|
|
"bbs-backend/config"
|
|
"bbs-backend/dal"
|
|
"fmt"
|
|
"github.com/gin-contrib/cors"
|
|
)
|
|
|
|
func main() {
|
|
// Load configuration
|
|
config.LoadConfig("config/config.yaml")
|
|
|
|
// Initialize the database
|
|
dal.InitDB()
|
|
|
|
// Migrate and seed the database
|
|
dal.MigrateAndSeedDB()
|
|
|
|
// Setup the router
|
|
r := router.SetupRouter()
|
|
|
|
// 添加 CORS 中间件
|
|
r.Use(cors.New(cors.Config{
|
|
AllowOrigins: []string{"http://localhost:8080"}, // 允许的源
|
|
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
|
ExposeHeaders: []string{"Content-Length"},
|
|
AllowCredentials: true,
|
|
}))
|
|
|
|
// Run the server
|
|
r.Run(fmt.Sprintf(":%d", config.GetConfig().Server.Port))
|
|
}
|