static icon indicating copy to clipboard operation
static copied to clipboard

How to use static middleware and cors middleware together?

Open penggy opened this issue 7 years ago • 1 comments

How to use static middleware and cors middleware together?

penggy avatar May 02 '18 10:05 penggy

    r := gin.Default()
    r.Use(gin.Logger())
    r.Use(gin.Recovery())
    r.Use(cors.New(cors.Config{
	AllowOrigins:     []string{"*"},
	AllowMethods:     []string{"GET", "POST", "PUT"},
	AllowHeaders:     []string{"Origin", "Content-Length", "Content-Type", "Authorization"},
	AllowCredentials: true,
	//AllowAllOrigins:  true,
	MaxAge: 12 * time.Hour,
    }))
    ui := r.Group("/")
    ui.StaticFS("/", http.Dir("./static"))

hmmftg avatar Jul 28 '22 10:07 hmmftg