30 lines
738 B
Go
30 lines
738 B
Go
package main
|
||
|
||
import (
|
||
"server/models"
|
||
_ "server/routers"
|
||
"server/version"
|
||
|
||
beego "github.com/beego/beego/v2/server/web"
|
||
"github.com/beego/beego/v2/server/web/context"
|
||
)
|
||
|
||
func main() {
|
||
// 初始化数据库
|
||
models.Init(version.Version)
|
||
|
||
// CORS配置已移至router.go中统一管理
|
||
// 确保请求体被正确读取(包括 POST、PUT、PATCH)
|
||
beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context) {
|
||
method := ctx.Input.Method()
|
||
if method == "PUT" || method == "POST" || method == "PATCH" {
|
||
ctx.Input.CopyBody(1024 * 1024) // 1MB 缓冲区
|
||
}
|
||
})
|
||
|
||
// 静态资源:映射 /uploads 到本地 uploads 目录,供前端访问上传文件
|
||
beego.SetStaticPath("/uploads", "uploads")
|
||
|
||
beego.Run()
|
||
}
|