-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (30 loc) · 996 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
package main
import (
"os"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/1shubham7/calorymeter/api"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
router := gin.New()
router.Use(gin.Logger())
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"}, // Replace with your frontend's URL
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
AllowCredentials: true,
}))
router.POST("/food/create", api.AddFoodEntry)
router.GET("/entries", api.GetFoodEntries)
router.GET("/entry/:id", api.GetFoodEntryByID)
router.GET("/ingredient/:ingredient", api.GetFoodEntryByIngredient)
router.PUT("/entry/update/:id", api.UpdateFoodEntry)
router.PUT("/ingredient/update/:id", api.UpdateFoodIngredient)
router.DELETE("/entry/delete/:id", api.DeleteFoodEntry)
router.GET("/tip", api.GetTip)
router.Run(":" + port)
}