package middleware import ( "context" "net/http" "github.com/cloudwego/hertz/pkg/app" ) func CORS() app.HandlerFunc { return func(ctx context.Context, c *app.RequestContext) { c.Header("Access-Control-Allow-Origin", "*") c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") c.Header("Access-Control-Allow-Headers", "Origin, Content-Type, Authorization") c.Header("Access-Control-Max-Age", "86400") if string(c.Method()) == http.MethodOptions { c.AbortWithStatus(http.StatusNoContent) return } c.Next(ctx) } }