-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (68 loc) · 1.71 KB
/
main.go
File metadata and controls
79 lines (68 loc) · 1.71 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"go-api-infra/database"
"go-api-infra/models"
"go-api-infra/routes"
"log"
"os"
// "strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Println("⚠️ .env file not found, using system env")
}
// 1️⃣ Connect Database
database.Connect()
// 2️⃣ Auto migrate all models
database.DB.AutoMigrate(
&models.User{},
&models.News{},
&models.Image{},
&models.UserLinks{},
&models.ForumPost{},
&models.ForumReply{},
&models.ForumSection{},
&models.Event{},
&models.GuestBook{},
&models.Mading{},
&models.Teacher{},
&models.Eskul{},
&models.Achievement{},
&models.Portal{},
&models.Industry{},
&models.Certification{},
&models.Testimonial{},
)
// 3️⃣ Init Fiber
app := fiber.New()
// allowedOrigins := []string{
// "https://infra-adeli.synchronizeteams.my.id",
// "https://smkpluspelitanusantara.sch.id",
// "http://localhost:3000",
// "http://127.0.0.1:3000",
// "https://infra.synchronizeteams.my.id/api",
// }
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
AllowHeaders: "Origin, Content-Type, Accept, Authorization",
}))
// 4️⃣ Serve static uploads
app.Static("/uploads", "./uploads")
// 5️⃣ Setup API Routes
routes.SetupRoutes(app)
port := os.Getenv("APP_PORT")
if port == "" {
port = "3000" // fallback kalau .env kosong
}
// 6️⃣ Start Server
addr := fmt.Sprintf("0.0.0.0:%s", port)
log.Printf("🚀 Server running on %s\n", addr)
if err := app.Listen(addr); err != nil {
log.Fatalf("❌ Failed to start Fiber server: %v", err)
}
}