-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
42 lines (32 loc) · 833 Bytes
/
Copy pathinit.go
File metadata and controls
42 lines (32 loc) · 833 Bytes
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
package main
import (
"class-system/dao"
"class-system/router"
"github.com/flamego/flamego"
)
var (
F *flamego.Flame
)
func init() {
_ = dao.InitPG()
F = flamego.New()
// 添加基础中间件
F.Use(flamego.Logger())
F.Use(flamego.Recovery())
F.Use(flamego.Static(flamego.StaticOptions{
Directory: "public",
}))
// 添加 Renderer 中间件
F.Use(flamego.Renderer())
// 添加 CORS 中间件
F.Use(func(c flamego.Context) {
c.ResponseWriter().Header().Set("Access-Control-Allow-Origin", "*")
c.ResponseWriter().Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
c.ResponseWriter().Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization")
if c.Request().Method == "OPTIONS" {
c.ResponseWriter().WriteHeader(200)
return
}
})
router.RouteInit(F)
}