From 60c930881b87140367c1f3ab5678addd17b08fad Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 26 Mar 2023 17:54:02 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20a=20few=20useful=20middleware?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/app.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/commands/app.go b/commands/app.go index 5dcc552..5fddd11 100644 --- a/commands/app.go +++ b/commands/app.go @@ -3,6 +3,8 @@ package commands import ( "codeberg.org/danjones000/lenore/config" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2/middleware/logger" "github.com/spf13/cobra" "log" ) @@ -15,6 +17,17 @@ func app(cmd *cobra.Command, args []string) { app := fiber.New() conf := config.GetConfig() + app.Use(func(c *fiber.Ctx) error { + c.Set("X-Clacks-Overhead", "GNU Terry Pratchett, Robin Williams") + c.Next() + return nil + }) + app.Use(logger.New(logger.Config{ + Format: "${time} | ${status} | ${latency} | ${method} | ${path} | ${body}\n", + TimeFormat: "2006-01-02T15:04:05", + })) + app.Use(cors.New(cors.Config{MaxAge: 3600})) + app.Get("/", func(c *fiber.Ctx) error { return c.JSON(&conf) })