0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-03 03:10:05 -05:00

CORS middleware sucks... Let's make our own

This commit is contained in:
dragongoose 2023-06-07 12:25:37 -04:00
parent 6d4434db21
commit f3afc56f2c
No known key found for this signature in database
GPG key ID: 50DB99B921579009

14
main.go
View file

@ -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)