From f3afc56f2c66156bd389e4385ddd0abe10e13ba8 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Wed, 7 Jun 2023 12:25:37 -0400 Subject: [PATCH] CORS middleware sucks... Let's make our own --- main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0ac4ebc..9525183 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,10 @@ package main import ( "log" "os" - "safetwitch-backend/extractor/chat" "safetwitch-backend/routes" "strings" - "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) @@ -33,6 +31,13 @@ func notFoundHandler(context *gin.Context) { }) } +func CORS() gin.HandlerFunc { + return func(c *gin.Context) { + c.Writer.Header().Set("Access-Control-Allow-Origin", "*") + c.Next() + } +} + func main() { log.Println("Starting Safetwitch...") // check for env @@ -40,12 +45,9 @@ func main() { if env == "" { log.Fatalln("ENV Variable 'URL' is not present") } - - go chat.BeginTwitchChatConnection() - router := gin.New() + router.Use(CORS()) router.Use(gin.Recovery()) - router.Use(cors.Default()) router.Use(ErrorHandler) routes.SetRoutes(router)