43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"mchess_server/api/handler"
|
|
"mchess_server/api/websocket"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var cert_path = "/etc/letsencrypt/live/chess.sw-gross.de/"
|
|
var cert_file = cert_path + "fullchain.pem"
|
|
var key_file = cert_path + "privkey.pem"
|
|
|
|
func main() {
|
|
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
|
|
}
|
|
|
|
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)
|
|
|
|
if debugMode {
|
|
log.Println("Starting service WITHOUT TLS")
|
|
log.Fatal(router.Run(":8080"))
|
|
} else {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
log.Println("Starting in release mode")
|
|
log.Println("Starting service with TLS")
|
|
log.Fatal(router.RunTLS("chess.sw-gross.de:9999", cert_file, key_file))
|
|
}
|
|
}
|