diff --git a/auth-service/main.go b/auth-service/main.go index d64a975..98d04a8 100644 --- a/auth-service/main.go +++ b/auth-service/main.go @@ -2,16 +2,34 @@ package main import ( "blog/contracttesting/db" + "log" + "os" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" + "github.com/joho/godotenv" ) func main() { + db.InitDB() + defer db.CloseDB() + + db.CreateUsersTable() + db.CreateBlogPostsTable() + db.CreateCommentsTable() r := gin.Default() + err := godotenv.Load() + + if err != nil { + log.Println("Error loading .env file" + err.Error()) + } + + deploymentLink := os.Getenv("DEPLOYMENT_LINK") + deploymentLink2 := deploymentLink + "/" + // Configure CORS middleware config := cors.DefaultConfig() - config.AllowOrigins = []string{"https://haal-samachar.vercel.app/", "http://localhost:3000/", "https://haal-samachar.vercel.app", "http://localhost:3000"} // Add your frontend origin here + config.AllowOrigins = []string{deploymentLink2, "http://localhost:3000/", deploymentLink, "http://localhost:3000"} // Add your frontend origin here config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"} r.Use(cors.New(config)) db.InitDB() diff --git a/blog-service/main.go b/blog-service/main.go index ca1a403..2611071 100644 --- a/blog-service/main.go +++ b/blog-service/main.go @@ -2,9 +2,12 @@ package main import ( "blog/contracttesting/db" + "log" + "os" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" + "github.com/joho/godotenv" ) func main() { @@ -14,10 +17,19 @@ func main() { db.CreateUsersTable() db.CreateBlogPostsTable() db.CreateCommentsTable() + err := godotenv.Load() + + if err != nil { + log.Println("Error loading .env file" + err.Error()) + } + + deploymentLink := os.Getenv("DEPLOYMENT_LINK") + deploymentLink2 := deploymentLink + "/" + r := gin.Default() // Configure CORS middleware config := cors.DefaultConfig() - config.AllowOrigins = []string{"https://haal-samachar.vercel.app/", "http://localhost:3000/", "https://haal-samachar.vercel.app", "http://localhost:3000"} // Add your frontend origin here + config.AllowOrigins = []string{deploymentLink2, "http://localhost:3000/", deploymentLink, "http://localhost:3000"} // Add your frontend origin here config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"} r.Use(cors.New(config)) // Define routes diff --git a/comment-service/main.go b/comment-service/main.go index f85adb7..87bcf4c 100644 --- a/comment-service/main.go +++ b/comment-service/main.go @@ -2,12 +2,23 @@ package main import ( "blog/contracttesting/db" + "log" + "os" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" + "github.com/joho/godotenv" ) func main() { + err := godotenv.Load() + + if err != nil { + log.Println("Error loading .env file" + err.Error()) + } + + deploymentLink := os.Getenv("DEPLOYMENT_LINK") + deploymentLink2 := deploymentLink + "/" db.InitDB() defer db.CloseDB() @@ -17,7 +28,7 @@ func main() { r := gin.Default() // Configure CORS middleware config := cors.DefaultConfig() - config.AllowOrigins = []string{"https://haal-samachar.vercel.app/", "http://localhost:3000/", "https://haal-samachar.vercel.app", "http://localhost:3000"} // Add your frontend origin here + config.AllowOrigins = []string{deploymentLink2, "http://localhost:3000/", deploymentLink, "http://localhost:3000"} // Add your frontend origin here config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"} r.Use(cors.New(config)) diff --git a/docker-compose.yml b/docker-compose.yml index a6e8ffc..1e8307f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,20 +27,20 @@ services: env_file: - .env - auth: + graphql: build: context: . - dockerfile: Dockerfile.auth + dockerfile: Dockerfile.graphql ports: - - "8084:8084" + - "8080:8080" env_file: - .env - - # frontend: - # build: - # context: . - # dockerfile: Dockerfile.frontend - # ports: - # - "3000:3000" - # env_file: - # - .env \ No newline at end of file + + frontend: + build: + context: . + dockerfile: Dockerfile.frontend + ports: + - "3000:3000" + env_file: + - .env \ No newline at end of file diff --git a/user-service/main.go b/user-service/main.go index 9a0e39f..c572919 100644 --- a/user-service/main.go +++ b/user-service/main.go @@ -2,10 +2,12 @@ package main import ( "log" + "os" "blog/contracttesting/db" "github.com/gin-gonic/gin" + "github.com/joho/godotenv" "github.com/gin-contrib/cors" ) @@ -20,9 +22,18 @@ func main() { db.CreateCommentsTable() // Create a new Gin router r := gin.Default() + + err := godotenv.Load() + + if err != nil { + log.Println("Error loading .env file" + err.Error()) + } + + deploymentLink := os.Getenv("DEPLOYMENT_LINK") + deploymentLink2 := deploymentLink + "/" // Configure CORS middleware config := cors.DefaultConfig() - config.AllowOrigins = []string{"https://haal-samachar.vercel.app/", "http://localhost:3000/", "https://haal-samachar.vercel.app", "http://localhost:3000"} // Add your frontend origin here + config.AllowOrigins = []string{deploymentLink2, "http://localhost:3000/", deploymentLink, "http://localhost:3000"} // Add your frontend origin here config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"} r.Use(cors.New(config))