From a7c282ca348c1e8e60559e5c064caee28ba11eec Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:34:12 +0300 Subject: refactor: so much shit --- backend/go.mod | 1 + backend/go.sum | 2 ++ backend/handlers/login.go | 2 ++ backend/main.go | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+) (limited to 'backend') diff --git a/backend/go.mod b/backend/go.mod index f6eef48..ae50685 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -8,6 +8,7 @@ require ( ) require ( + github.com/gin-contrib/cors v1.7.2 github.com/golang-jwt/jwt/v4 v4.5.0 github.com/google/uuid v1.6.0 github.com/pektezol/steam_go v1.1.2 diff --git a/backend/go.sum b/backend/go.sum index 10504e4..f117b31 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -31,6 +31,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= +github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw= +github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E= github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= diff --git a/backend/handlers/login.go b/backend/handlers/login.go index 565ebdb..408d950 100644 --- a/backend/handlers/login.go +++ b/backend/handlers/login.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io" + "log" "net/http" "os" "time" @@ -29,6 +30,7 @@ type LoginResponse struct { // @Success 200 {object} models.Response{data=LoginResponse} // @Router /login [get] func Login(c *gin.Context) { + log.Println(c.Request.Host) openID := steam_go.NewOpenID(c.Request, true) switch openID.Mode() { case "": diff --git a/backend/main.go b/backend/main.go index 202c607..306823c 100644 --- a/backend/main.go +++ b/backend/main.go @@ -4,11 +4,13 @@ import ( "fmt" "log" "os" + "time" "lphub/api" "lphub/database" _ "lphub/docs" + "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" "github.com/joho/godotenv" ) @@ -31,7 +33,23 @@ func main() { gin.SetMode(gin.ReleaseMode) } router := gin.Default() + router.Use(cors.New(cors.Config{ + AllowOrigins: []string{"*"}, + AllowMethods: []string{"GET", "POST", "DELETE", "PUT", "PATCH"}, + AllowHeaders: []string{"Origin"}, + ExposeHeaders: []string{"Content-Length"}, + AllowCredentials: true, + AllowOriginFunc: func(origin string) bool { + return origin == "https://github.com" + }, + MaxAge: 12 * time.Hour, + })) database.ConnectDB() api.InitRoutes(router) + router.Static("/static", "../frontend/build/static") + router.StaticFile("/", "../frontend/build/index.html") + router.NoRoute(func(c *gin.Context) { + c.File("../frontend/build/index.html") + }) router.Run(fmt.Sprintf(":%s", os.Getenv("PORT"))) } -- cgit v1.2.3