mchess-server/main.go

46 lines
1.3 KiB
Go
Raw Normal View History

2022-10-22 18:01:55 +00:00
package main
import (
2023-09-01 13:29:26 +00:00
"flag"
"log"
"mchess_server/api/handler"
"mchess_server/api/websocket"
2023-04-18 20:12:05 +00:00
"github.com/gin-gonic/gin"
2022-10-22 18:01:55 +00:00
)
var cert_path = "/etc/letsencrypt/live/chess.sw-gross.de/"
var cert_file = cert_path + "fullchain.pem"
var key_file = cert_path + "privkey.pem"
2023-04-18 20:12:05 +00:00
func main() {
2023-09-01 13:29:26 +00:00
var debugMode bool
debugModeLong := flag.Bool("debug", false, "activates debug mode")
debugModeShort := flag.Bool("d", false, "activates debug mode")
flag.Parse()
if *debugModeShort || *debugModeLong {
debugMode = true
2022-12-18 14:43:27 +00:00
}
2023-04-18 20:12:05 +00:00
router := gin.Default()
router.GET("/api/random", handler.RegisterForRandomGame)
router.GET("/api/hostPrivate", handler.HostPrivateGameHandler)
router.POST("/api/joinPrivate", handler.JoinPrivateGame)
router.GET("/api/ws", websocket.RegisterWebSocketConnection)
router.GET("/api/getLobbyForPassphrase/:phrase", handler.GetLobbyForPassphraseHandler)
router.GET("/api/registerWsForGame/:id", websocket.ConnectWsForGame)
router.POST("/api/joinGame/:id", handler.JoinGame)
2022-11-19 10:41:10 +00:00
2023-09-01 13:29:26 +00:00
if debugMode {
2023-04-18 20:12:05 +00:00
log.Println("Starting service WITHOUT TLS")
log.Fatal(router.Run(":8080"))
} else {
2023-06-06 20:58:33 +00:00
gin.SetMode(gin.ReleaseMode)
log.Println("Starting in release mode")
log.Println("Starting service with TLS")
2023-06-06 21:23:28 +00:00
log.Fatal(router.RunTLS("chess.sw-gross.de:9999", cert_file, key_file))
2022-11-19 10:41:10 +00:00
}
2023-04-18 20:12:05 +00:00
}