This repository has been archived on 2025-11-25. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
combluotion-old/app/app.go
2023-03-27 20:48:25 -05:00

41 lines
914 B
Go

package app
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"
)
func New() *fiber.App {
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)
})
app.Post("/check_pass", func(c *fiber.Ctx) error {
req := new(struct {
Pass string `json:"pass"`
})
if err := c.BodyParser(req); err != nil {
panic(err)
}
return c.JSON(config.CheckPassword(req.Pass))
})
return app
}