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:
parent
6d4434db21
commit
f3afc56f2c
1 changed files with 8 additions and 6 deletions
14
main.go
14
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)
|
||||
|
|
Loading…
Reference in a new issue