cors.go 478 B

123456789101112131415161718
  1. package middleware
  2. import (
  3. "github.com/gin-contrib/cors"
  4. "github.com/gin-gonic/gin"
  5. "time"
  6. )
  7. func Cors() gin.HandlerFunc {
  8. return cors.New(cors.Config{
  9. AllowOrigins: []string{"*"}, // 允许所有来源
  10. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  11. AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
  12. ExposeHeaders: []string{"Content-Length"},
  13. AllowCredentials: true,
  14. MaxAge: 12 * time.Hour,
  15. })
  16. }