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/commands/app.go

53 lines
1.2 KiB
Go
Raw Normal View History

2023-03-24 13:03:21 -05:00
package commands
import (
2023-03-25 20:42:54 -05:00
"codeberg.org/danjones000/lenore/config"
2023-03-24 13:03:21 -05:00
"github.com/gofiber/fiber/v2"
2023-03-26 17:54:02 -05:00
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
2023-03-24 13:03:21 -05:00
"github.com/spf13/cobra"
"log"
)
type passReq struct {
Pass string `json:"pass"`
}
func app(cmd *cobra.Command, args []string) {
app := fiber.New()
conf := config.GetConfig()
2023-03-26 17:54:02 -05:00
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}))
2023-03-24 13:03:21 -05:00
app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(&conf)
})
app.Post("/check_pass", func(c *fiber.Ctx) error {
req := new(passReq)
if err := c.BodyParser(req); err != nil {
panic(err)
}
return c.JSON(config.CheckPassword(req.Pass))
})
log.Fatal(app.Listen(":3000"))
}
var AppCmd = &cobra.Command{
Use: "app",
2023-03-25 20:42:54 -05:00
Short: "Run the lenore webapp",
2023-03-24 13:03:21 -05:00
Long: `This is the main command. This will start the application, and keep it running.
You may want to run this from something like supervisor or systemd`,
Run: app,
}