Files
kontor/kontor-fiber/cmd/kontor/main.go
T
Thomas Peetz f2f4a0aaf6
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
add templates for kontor-gin
2026-09-21 19:55:46 +02:00

61 lines
1.3 KiB
Go

package main
import (
"kontor-api-fiber/pkg/handler"
"kontor-api-fiber/pkg/schema"
"kontor-api-fiber/pkg/web"
"log"
"time"
jwtware "github.com/gofiber/contrib/v3/jwt"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/logger"
"github.com/gofiber/fiber/v3/middleware/static"
"github.com/gofiber/template/html/v3"
)
func main() {
log.Println("Kontor started")
if err := schema.Connect(); err != nil {
log.Fatal(err)
}
// Create a new engine
engine := html.New("./views", ".html")
app := fiber.New(fiber.Config{
Views: engine,
ViewsLayout: "layouts/main",
})
//app.Use(logger.New())
app.Get("/health", handler.GetHealth)
app.Post("/login", handler.Login)
web.SetupRoutes(app)
//api := app.Group("/api/v1")
api := app.Group("/api/v1", logger.New(), jwtware.New(jwtware.Config{
SigningKey: jwtware.SigningKey{Key: []byte("secret")},
}))
api.Use(logger.New())
handler.SetupComicRoutes(api)
handler.SetupMediaRoutes(api)
app.Get("/*", static.New("./static", static.Config{
Browse: false,
MaxAge: 3600,
CacheDuration: 10 * time.Second,
NotFoundHandler: func(c fiber.Ctx) error {
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
"error": "asset not found",
"path": c.Path(),
})
},
}))
// Listen on port 8900
app.Listen(":8500")
log.Println("Kontor finished")
}