初始化v1
This commit is contained in:
19
api/middleware/cors.go
Normal file
19
api/middleware/cors.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// CORS 跨域处理中间件
|
||||
func CORS(r *ghttp.Request) {
|
||||
// 设置CORS头
|
||||
r.Response.CORSDefault()
|
||||
|
||||
// 处理预检请求
|
||||
if r.Method == "OPTIONS" {
|
||||
r.Response.WriteHeader(200)
|
||||
return
|
||||
}
|
||||
|
||||
r.Middleware.Next()
|
||||
}
|
||||
Reference in New Issue
Block a user