forked from pclubiitk/puppylove2.0_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (38 loc) · 1.25 KB
/
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
package main
import (
"os"
// "github.com/gin-contrib/cors"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/pclubiitk/puppylove2.0_backend/db"
"github.com/pclubiitk/puppylove2.0_backend/router"
"github.com/pclubiitk/puppylove2.0_backend/utils"
)
func main() {
// Load environment variables from .env file
if err := godotenv.Load(); err != nil {
panic("Error loading .env file")
}
var CfgAdminPass = os.Getenv("CFG_ADMIN_PASS")
Db := db.InitDB()
utils.Randinit()
store := cookie.NewStore([]byte(CfgAdminPass))
r := gin.Default()
// Local Testing Frontend Running on localhost:3000
// r.Use(cors.New(cors.Config{AllowCredentials: true, AllowOrigins: []string{"http://localhost:3000"}, AllowHeaders: []string{"content-type"}}))
// Allow all origins
r.Use(cors.New(cors.Config{
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool { return true },
AllowHeaders: []string{"content-type", "g-recaptcha-response"},
}))
r.Use(sessions.Sessions("adminsession", store))
router.PuppyRoute(r, *Db)
r.Run(":8080")
// if err := r.Run(config.CfgAddr); err != nil {
// fmt.Println("[Error] " + err.Error())
// }
}