2022-10-22 18:01:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-01 13:29:26 +00:00
|
|
|
"flag"
|
2023-06-29 20:20:41 +00:00
|
|
|
"log"
|
2024-05-11 10:03:24 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2022-12-18 01:49:10 +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()
|
2024-05-09 20:29:48 +00:00
|
|
|
router.GET("/api/random", handler.RegisterForRandomGame)
|
|
|
|
router.GET("/api/hostPrivate", handler.HostPrivateGameHandler)
|
|
|
|
router.POST("/api/joinPrivate", handler.JoinPrivateGame)
|
2024-05-11 10:03:24 +00:00
|
|
|
router.GET("/api/ws", websocket.RegisterWebSocketConnection)
|
2024-05-09 20:29:48 +00:00
|
|
|
router.GET("/api/getLobbyForPassphrase/:phrase", handler.GetLobbyForPassphraseHandler)
|
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")
|
2023-09-23 23:15:52 +00:00
|
|
|
log.Fatal(router.Run(":8080"))
|
2022-12-18 14:56:06 +00:00
|
|
|
} 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
|
|
|
}
|