From a7c282ca348c1e8e60559e5c064caee28ba11eec Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:34:12 +0300 Subject: refactor: so much shit --- backend/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'backend/main.go') 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 ( "fmt" "log" "os" + "time" "lphub/api" "lphub/database" _ "lphub/docs" + "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" "github.com/joho/godotenv" ) @@ -31,7 +33,23 @@ func main() { gin.SetMode(gin.ReleaseMode) } router := gin.Default() + router.Use(cors.New(cors.Config{ + AllowOrigins: []string{"*"}, + AllowMethods: []string{"GET", "POST", "DELETE", "PUT", "PATCH"}, + AllowHeaders: []string{"Origin"}, + ExposeHeaders: []string{"Content-Length"}, + AllowCredentials: true, + AllowOriginFunc: func(origin string) bool { + return origin == "https://github.com" + }, + MaxAge: 12 * time.Hour, + })) database.ConnectDB() api.InitRoutes(router) + router.Static("/static", "../frontend/build/static") + router.StaticFile("/", "../frontend/build/index.html") + router.NoRoute(func(c *gin.Context) { + c.File("../frontend/build/index.html") + }) router.Run(fmt.Sprintf(":%s", os.Getenv("PORT"))) } -- cgit v1.2.3