From 22e99431f67a92a41d44168e03628ffd114012af Mon Sep 17 00:00:00 2001 From: iamjooon2 Date: Tue, 11 Feb 2025 18:29:21 +0900 Subject: [PATCH 1/4] =?UTF-8?q?build:=20cors=20=EC=9D=98=EC=A1=B4=EC=84=B1?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 + go.sum | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/go.mod b/go.mod index 2a51224..d26d3a9 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/cloudwego/iasm v0.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.7 // indirect + github.com/gin-contrib/cors v1.7.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-playground/locales v0.14.1 // indirect diff --git a/go.sum b/go.sum index ab84d96..27d9e1f 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= +github.com/gin-contrib/cors v1.7.3 h1:hV+a5xp8hwJoTw7OY+a70FsL8JkVVFTXw9EcfrYUdns= +github.com/gin-contrib/cors v1.7.3/go.mod h1:M3bcKZhxzsvI+rlRSkkxHyljJt1ESd93COUvemZ79j4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= @@ -60,6 +62,7 @@ github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -144,6 +147,7 @@ google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 529f21c6da870c9d13c1b19c21842661caf1f03b Mon Sep 17 00:00:00 2001 From: iamjooon2 Date: Tue, 11 Feb 2025 18:32:58 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index 263a1ff..e3abd60 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,6 +3,7 @@ package main import ( "log" + "github.com/gin-contrib/cors" "github.com/joho/godotenv" "github.com/techbloghub/server/config" "github.com/techbloghub/server/ent" @@ -43,6 +44,14 @@ func createServer(cfg *config.Config) (*gin.Engine, *ent.Client, error) { } r := gin.Default() + corsConfig := cors.Config{ + AllowOrigins: []string{"https://techbloghub.net"}, + AllowMethods: []string{"GET", "POST", "OPTIONS", "DELETE", "PUT", "PATCH"}, + AllowHeaders: []string{"Origin", "Content-Type", "Authorization"}, + ExposeHeaders: []string{"Content-Length"}, + } + r.Use(cors.New(corsConfig)) + router.InitRouter(r, client) return r, client, nil From 5059642be2e506c0b2ced30e18105f8149cf41f4 Mon Sep 17 00:00:00 2001 From: iamjooon2 Date: Fri, 14 Feb 2025 21:58:10 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20CORS=20Origin=20=EB=AA=A8=EB=93=A0?= =?UTF-8?q?=20=EC=9E=90=EC=9B=90=EC=97=90=20=EB=8C=80=ED=95=B4=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index e3abd60..aca38c8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -45,7 +45,7 @@ func createServer(cfg *config.Config) (*gin.Engine, *ent.Client, error) { r := gin.Default() corsConfig := cors.Config{ - AllowOrigins: []string{"https://techbloghub.net"}, + AllowOrigins: []string{"*"}, AllowMethods: []string{"GET", "POST", "OPTIONS", "DELETE", "PUT", "PATCH"}, AllowHeaders: []string{"Origin", "Content-Type", "Authorization"}, ExposeHeaders: []string{"Content-Length"}, From 0c251974a4b98bb862ef8cc7aece93ecd7cb2fca Mon Sep 17 00:00:00 2001 From: iamjooon2 Date: Fri, 14 Feb 2025 23:31:27 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20CORS=20Origins=20=ED=94=84=EB=A1=A0?= =?UTF-8?q?=ED=8A=B8=EC=99=80=20=EB=A1=9C=EC=BB=AC=ED=98=B8=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A7=8C=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index aca38c8..59376b5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -45,7 +45,7 @@ func createServer(cfg *config.Config) (*gin.Engine, *ent.Client, error) { r := gin.Default() corsConfig := cors.Config{ - AllowOrigins: []string{"*"}, + AllowOrigins: []string{"https://techbloghub.net", "https://localhost:3000", "http://localhost:3000"}, AllowMethods: []string{"GET", "POST", "OPTIONS", "DELETE", "PUT", "PATCH"}, AllowHeaders: []string{"Origin", "Content-Type", "Authorization"}, ExposeHeaders: []string{"Content-Length"},