Skip to content

Commit

Permalink
Changed Deployment URL to allow CORS
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Singh <[email protected]>
  • Loading branch information
SkySingh04 committed May 1, 2024
1 parent 9665115 commit 042cb20
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
20 changes: 19 additions & 1 deletion auth-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 13 additions & 1 deletion blog-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion comment-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))

Expand Down
24 changes: 12 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

frontend:
build:
context: .
dockerfile: Dockerfile.frontend
ports:
- "3000:3000"
env_file:
- .env
13 changes: 12 additions & 1 deletion user-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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))

Expand Down

0 comments on commit 042cb20

Please sign in to comment.