package app import ( "os" "system-trace/core/app/constants" "system-trace/core/app/router" "system-trace/core/auth/middlewares" "system-trace/core/environment" "github.com/goccy/go-json" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/recover" ) var Instance *fiber.App func Serve() { Instance = initServer() Instance.Use(recover.New()) Instance.Use(cors.New()) Instance.Use(middlewares.ValidateSession) router.Init(Instance) Instance.Use(func(c *fiber.Ctx) error { return c. Status(fiber.StatusNotFound). JSON(fiber.Map{ "error": constants.NOT_FOUND, }) }) Instance.Listen(":" + os.Getenv("APP_PORT")) } func initServer() *fiber.App { debug := environment.IsDebug() return fiber.New(fiber.Config{ JSONEncoder: json.Marshal, JSONDecoder: json.Unmarshal, CaseSensitive: true, EnablePrintRoutes: debug, Prefork: true, AppName: "System Trace API", ErrorHandler: func(c *fiber.Ctx, err error) error { return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ "error": err.Error(), }) }, }) }