-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (32 loc) · 897 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
package main
import (
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/harshit-jain52/LinkTree/configs"
"github.com/harshit-jain52/LinkTree/routes"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Link struct {
ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
Title string `json:"title"`
Url string `json:"url"`
}
func main() {
configs.ConnectDB()
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:5173/",
AllowHeaders: "Origin,Content-Type,Accept,Authorization",
}))
routes.UserRoutes(app)
routes.LinksRoutes(app)
if os.Getenv("ENV") == "production" {
app.Static("/", "./client/dist")
app.Get("/*", func(c *fiber.Ctx) error {
return c.SendFile("./client/dist/index.html")
})
}
log.Fatal(app.Listen(":" + configs.EnvPort()))
}