ManagementSystem/main.go

86 lines
1.8 KiB
Go
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

// Package classification Click 'n' Join ManagementSystem Documentation.
//
// Exclusively for requests from the Admin Dashboard.
// Not for use from the main app!
//
// Schemes: http
// Host: localhost
// BasePath: /v1
// Version: 0.0.1
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
package main
import (
"time"
"clickandjoin.app/managementsystem/modules/config"
"clickandjoin.app/managementsystem/modules/rabbitmq"
"clickandjoin.app/managementsystem/modules/scylladb"
"clickandjoin.app/managementsystem/routers/router"
"clickandjoin.app/managementsystem/socketserver"
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/websocket/v2"
)
func init() {
config.LoadConfig()
gocnjhelper.InitLogger(config.Cfg.Debug, true, false, "", 0, 0)
scylladb.InitDatabase()
go rabbitmq.Init()
}
func main() {
app := fiber.New()
//app.Use(cors.New())
app.Static("/dist", "dist")
cfg := config.Cfg
if cfg.Debug {
app.Use(logger.New(logger.Config{
Format: "${pid} ${locals:requestid} ${status} - ${method} ${path}\n",
}))
}
app.Use("/ws", func(c *fiber.Ctx) error {
// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
if websocket.IsWebSocketUpgrade(c) {
authKey := c.Query("auth")
// no auth query available
if authKey != cfg.ManagementSystemWebSocketKey {
return c.SendStatus(fiber.StatusUnauthorized)
}
return c.Next()
}
return fiber.ErrUpgradeRequired
})
go socketserver.RunHub()
socketserver.WebSocketServer(app)
router.SetupRoutes(app)
gocnjhelper.LogInfof("%s", time.Now().UnixMilli())
app.Listen(cfg.Host + ":" + cfg.Port)
}