2023-05-25 20:04:15 -05:00
|
|
|
package root
|
|
|
|
|
|
|
|
import (
|
|
|
|
"safetwitch-backend/extractor"
|
2023-05-30 09:22:20 -05:00
|
|
|
"safetwitch-backend/extractor/chat"
|
2023-05-25 20:04:15 -05:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-05-30 09:22:20 -05:00
|
|
|
"github.com/gobwas/ws"
|
2023-05-25 20:04:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func Routes(route *gin.Engine) {
|
|
|
|
auth := route.Group("/")
|
|
|
|
|
|
|
|
auth.GET("/", func(context *gin.Context) {
|
2023-05-30 09:22:20 -05:00
|
|
|
upgradeHeader := context.Request.Header.Get("Upgrade")
|
|
|
|
if upgradeHeader == "websocket" {
|
|
|
|
conn, _, _, err := ws.UpgradeHTTP(context.Request, context.Writer)
|
|
|
|
if err != nil {
|
|
|
|
context.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go chat.CreateWebsocketServer(conn, context)
|
|
|
|
} else {
|
|
|
|
context.JSON(200, extractor.FormatMessage("SafeTwitch backend running", true))
|
|
|
|
}
|
2023-05-25 20:04:15 -05:00
|
|
|
})
|
|
|
|
}
|