-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (44 loc) · 988 Bytes
/
main.go
File metadata and controls
54 lines (44 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"log"
"os"
"gradientfit/backend/database"
"gradientfit/backend/models"
"gradientfit/backend/routes"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
if err := database.Connect(); err != nil {
log.Fatal(err)
}
database.DB.AutoMigrate(
&models.User{},
&models.Product{},
&models.Image{},
&models.Variant{},
&models.Cart{},
&models.CartItem{},
)
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:3000",
AllowHeaders: "Origin, Content-Type, Accept, Authorization",
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
}))
routes.UserRoutes(app)
routes.ProductRoutes(app)
routes.ImageRoutes(app)
routes.VariantRoutes(app)
routes.CartRoutes(app)
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
log.Fatal(app.Listen(":" + port))
}