Skip to content

Commit

Permalink
changed cors config -> now delete and patch request allowed
Browse files Browse the repository at this point in the history
removed requirement of .env file
  • Loading branch information
relaxgameing committed Oct 23, 2024
1 parent 66cf89e commit ecfa1e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
environment:
MONGODB_URI: <db_connection_string>
PORT: "5000"
ENV: development
ENV: production
ports:
- "5000:5000"

Expand Down
18 changes: 9 additions & 9 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"

"github.com/gofiber/fiber/v2"
"github.com/joho/godotenv"
"github.com/gofiber/fiber/v2/middleware/cors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
Expand All @@ -27,10 +27,10 @@ func main() {

if os.Getenv("ENV") != "production" {
// Load the .env file if not in production
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file:", err)
}
// err := godotenv.Load(".env")
// if err != nil {
// log.Fatal("Error loading .env file:", err)
// }
}

MONGODB_URI := os.Getenv("MONGODB_URI")
Expand All @@ -54,10 +54,10 @@ func main() {

app := fiber.New()

// app.Use(cors.New(cors.Config{
// AllowOrigins: "http://localhost:5173",
// AllowHeaders: "Origin,Content-Type,Accept",
// }))
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:5173",
AllowHeaders: "Origin,Content-Type,Accept",
}))

app.Get("/api/todos", getTodos)
app.Post("/api/todos", createTodo)
Expand Down

0 comments on commit ecfa1e4

Please sign in to comment.