aboutsummaryrefslogtreecommitdiff
path: root/backend/main.go
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-09 16:34:12 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-09 16:34:12 +0300
commita7c282ca348c1e8e60559e5c064caee28ba11eec (patch)
tree43bd7bdb2bbc80b92b96a14b36c33f0b7df622c9 /backend/main.go
parentRankings page (diff)
downloadlphub-a7c282ca348c1e8e60559e5c064caee28ba11eec.tar.gz
lphub-a7c282ca348c1e8e60559e5c064caee28ba11eec.tar.bz2
lphub-a7c282ca348c1e8e60559e5c064caee28ba11eec.zip
refactor: so much shit
Diffstat (limited to 'backend/main.go')
-rw-r--r--backend/main.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/backend/main.go b/backend/main.go
index 202c607..306823c 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -4,11 +4,13 @@ import (
4 "fmt" 4 "fmt"
5 "log" 5 "log"
6 "os" 6 "os"
7 "time"
7 8
8 "lphub/api" 9 "lphub/api"
9 "lphub/database" 10 "lphub/database"
10 _ "lphub/docs" 11 _ "lphub/docs"
11 12
13 "github.com/gin-contrib/cors"
12 "github.com/gin-gonic/gin" 14 "github.com/gin-gonic/gin"
13 "github.com/joho/godotenv" 15 "github.com/joho/godotenv"
14) 16)
@@ -31,7 +33,23 @@ func main() {
31 gin.SetMode(gin.ReleaseMode) 33 gin.SetMode(gin.ReleaseMode)
32 } 34 }
33 router := gin.Default() 35 router := gin.Default()
36 router.Use(cors.New(cors.Config{
37 AllowOrigins: []string{"*"},
38 AllowMethods: []string{"GET", "POST", "DELETE", "PUT", "PATCH"},
39 AllowHeaders: []string{"Origin"},
40 ExposeHeaders: []string{"Content-Length"},
41 AllowCredentials: true,
42 AllowOriginFunc: func(origin string) bool {
43 return origin == "https://github.com"
44 },
45 MaxAge: 12 * time.Hour,
46 }))
34 database.ConnectDB() 47 database.ConnectDB()
35 api.InitRoutes(router) 48 api.InitRoutes(router)
49 router.Static("/static", "../frontend/build/static")
50 router.StaticFile("/", "../frontend/build/index.html")
51 router.NoRoute(func(c *gin.Context) {
52 c.File("../frontend/build/index.html")
53 })
36 router.Run(fmt.Sprintf(":%s", os.Getenv("PORT"))) 54 router.Run(fmt.Sprintf(":%s", os.Getenv("PORT")))
37} 55}