Skip to content

Commit

Permalink
fix: cors invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Apr 12, 2024
1 parent a67a84f commit a5a9ae5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion backend/controller/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller

import (
"time"

"github.com/RockChinQ/Campux/backend/service"
"github.com/RockChinQ/Campux/backend/util"
"github.com/gin-contrib/cors"
Expand All @@ -18,7 +20,21 @@ func NewApiController(
r := gin.Default()

if gin.Mode() == gin.DebugMode {
r.Use(cors.Default())
r.Use(
cors.New(
cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return true
},
MaxAge: 12 * time.Hour,
},
),
)
}

rg := r.Group("/v1")
Expand Down

0 comments on commit a5a9ae5

Please sign in to comment.