87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
// Package classification Click 'n' Join ManagementSystem Documentation.
|
||
//
|
||
// Exclusively for requests via the Admin Dashboard.
|
||
// Not for use in the main app!
|
||
//
|
||
// Schemes: http
|
||
// Host: localhost
|
||
// BasePath: /v1
|
||
// Version: 0.0.1
|
||
//
|
||
// Consumes:
|
||
// - application/json
|
||
//
|
||
// Produces:
|
||
// - application/json
|
||
//
|
||
// swagger:meta
|
||
package main
|
||
|
||
import (
|
||
"clickandjoin.app/managementsystem/modules/config"
|
||
"clickandjoin.app/managementsystem/modules/rabbitmq"
|
||
"clickandjoin.app/managementsystem/modules/scylladb"
|
||
"clickandjoin.app/managementsystem/modules/utils"
|
||
"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() {
|
||
utils.ValidatorInit()
|
||
|
||
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 scylladb.TableCleaner()
|
||
|
||
go socketserver.RunHub()
|
||
|
||
socketserver.WebSocketServer(app)
|
||
|
||
router.SetupRoutes(app)
|
||
|
||
app.Listen(cfg.Host + ":" + cfg.Port)
|
||
}
|