main.go 808 B

1234567891011121314151617181920212223
  1. package main
  2. import (
  3. "cc-officialweb/middleware"
  4. _ "cc-officialweb/routers"
  5. beego "github.com/beego/beego/v2/server/web"
  6. "github.com/beego/beego/v2/server/web/filter/cors"
  7. )
  8. func main() {
  9. beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
  10. AllowAllOrigins: true,
  11. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  12. AllowHeaders: []string{"Origin", "Content-Type", "Authorization", "X-Requested-With"},
  13. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},
  14. AllowCredentials: true,
  15. }))
  16. beego.InsertFilter("/api/*", beego.BeforeRouter, middleware.AuthMiddleware)
  17. beego.SetStaticPath("/image", "./static/upload")
  18. beego.SetStaticPath("/file", "./static/file")
  19. beego.SetStaticPath("/assets", "./static/assets")
  20. beego.Run()
  21. }