Skip to content

Commit

Permalink
Merge pull request #45 from openhacku-team-a/fix-middleware-auth-1034
Browse files Browse the repository at this point in the history
🐛 CORS用Middlewareの入れ方を変更
  • Loading branch information
pirotyyy authored Mar 16, 2024
2 parents dccfd5b + 6ba57fb commit d748e61
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions svc/cmd/dev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"a-project-backend/svc/pkg/handler"
"a-project-backend/svc/pkg/middleware"
"fmt"
"log"
"time"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"log"
"time"
)

func main() {
Expand Down Expand Up @@ -50,10 +49,16 @@ func main() {
}

engine := gin.Default()
engine.Use(cors.New(cors.Config{

engine.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
})
apiV1 := engine.Group("/api/v1")
apiV1.Use(cors.New(cors.Config{
// アクセスを許可したいアクセス元
AllowOrigins: []string{
"http://localhost:3000",
"https://main.a.shion.pro",
},
// アクセスを許可したいHTTPメソッド(以下の例だとPUTやDELETEはアクセスできません)
AllowMethods: []string{
Expand All @@ -77,11 +82,6 @@ func main() {
// preflightリクエストの結果をキャッシュする時間
MaxAge: 24 * time.Hour,
}))

engine.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
})
apiV1 := engine.Group("/api/v1")
if err := Implement(apiV1, db, g); err != nil {
log.Fatalf("Failed to start server... %v", err)
return
Expand Down

0 comments on commit d748e61

Please sign in to comment.