19 lines
290 B
Go
19 lines
290 B
Go
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()
|
|
} |