mirror of
https://github.com/songquanpeng/message-pusher.git
synced 2025-09-27 04:26:31 +08:00
21 lines
647 B
Go
21 lines
647 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gin-gonic/contrib/cors"
|
|
"github.com/gin-gonic/gin"
|
|
"time"
|
|
)
|
|
|
|
func CORS() gin.HandlerFunc {
|
|
config := cors.DefaultConfig()
|
|
config.AllowedHeaders = []string{"Authorization", "Content-Type", "Origin",
|
|
"Connection", "Accept-Encoding", "Accept-Language", "Host"}
|
|
config.AllowedMethods = []string{"GET", "POST", "DELETE", "OPTIONS", "PUT"}
|
|
config.AllowCredentials = true
|
|
config.MaxAge = 12 * time.Hour
|
|
// if you want to allow all origins, comment the following two lines
|
|
config.AllowAllOrigins = false
|
|
config.AllowedOrigins = []string{"https://message-pusher.vercel.app"}
|
|
return cors.New(config)
|
|
}
|