-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (34 loc) · 939 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
package main
import (
"os"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/1shubham7/calorymeter/api"
"github.com/1shubham7/calorymeter/middleware"
"github.com/1shubham7/calorymeter/routes"
"github.com/1shubham7/calorymeter/websocket"
)
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"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
AllowCredentials: true,
}))
router.Use(middleware.PerClientTokenBucket())
pool := websocket.NewPool()
go pool.Start()
router.GET("/ws", func(c *gin.Context) {
api.ServeWS(pool, c.Writer, c.Request)
})
routes.FoodRoutes(router)
routes.UserRoutes(router)
routes.TipRoutes(router)
router.Run(":" + port)
}