gin-contrib / static

Static middleware
MIT License
290 stars 41 forks source link

How to use static middleware and cors middleware together? #9

Open penggy opened 6 years ago

penggy commented 6 years ago

How to use static middleware and cors middleware together?

hmmftg commented 2 years ago
    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"))