-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (35 loc) · 940 Bytes
/
main.go
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
package main
import (
"context"
"log"
"net/http"
"github.com/Nexthrive/NexText/db"
"github.com/Nexthrive/NexText/routes"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
// Get MongoDB client instance
client := db.GetMongoDBClient()
// Check the connection
err := client.Ping(context.Background(), nil)
if err != nil {
log.Fatalf("Failed to ping MongoDB: %v", err)
}
r := gin.Default()
// Use CORS middleware with specific configuration
config := cors.DefaultConfig()
config.AllowAllOrigins = true // Allow all origins, you can also set a specific origin
config.AllowHeaders = append(config.AllowHeaders, "Authorization")
r.Use(cors.New(config))
routes.UserRoutes(r)
routes.WebSocketRoutes(r)
routes.FriendRoutes(r)
r.Handle(http.MethodGet, "/", Handler)
r.Run(":8080")
}
func Handler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "Hello from the handler!",
})
}