123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package middleware
- import (
- "github.com/gin-contrib/cors"
- "github.com/gin-gonic/gin"
- "time"
- )
- var defaultCORSConfig = cors.Config{
- AllowAllOrigins: true,
- AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"},
- AllowHeaders: []string{
- "Origin",
- "Accept",
- "Accept-Language",
- "Content-Language",
- "Content-Type",
- "User-Agent",
- "Authorization",
- "x-timezone-offset",
- "x-user-id",
- "X-User-Id",
- "X-Rate-Limit-Token",
- "x-rate-limit-token",
- "X-Timezone-Name",
- "x-timezone-name",
- "X-Lingochamp-Id",
- "x-lingochamp-id",
- "x-user-language",
- },
- AllowCredentials: true,
- MaxAge: 12 * time.Hour,
- }
- // CORS enable CORS support
- func CORS(configs ...cors.Config) gin.HandlerFunc {
- if len(configs) != 0 {
- return cors.New(configs[0])
- }
- return cors.New(defaultCORSConfig)
- }
|