add templates for kontor-gin
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s

This commit is contained in:
Thomas Peetz
2026-09-22 19:19:51 +02:00
parent f2f4a0aaf6
commit 044da5353a
24 changed files with 603 additions and 101 deletions
+18 -20
View File
@@ -10,16 +10,18 @@ import (
"kontor-api-gin/pkg/schema"
"kontor-api-gin/templates"
"log"
"log/slog"
"net/http"
"os"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
gin_slog "github.com/gin-contrib/slog"
"github.com/gin-gonic/gin"
)
func main() {
log.Println("Kontor started")
slog.Info("Kontor started")
// Set Gin mode based on environment
// Production mode disables debug output
@@ -35,27 +37,30 @@ func main() {
// Create Gin router with default middleware
// Default includes Logger and Recovery middleware
//router := gin.Default()
// router := gin.Default()
// Create a new router without default mmiddleware
router := gin.New()
// Add recovery middleware
router.Use(gin.Recovery())
router.Use(gin_slog.SetLogger(
gin_slog.WithSkipPath([]string{"/health", "/public/style/main.css"}),
gin_slog.WithDefaultLevel(slog.LevelInfo),
gin_slog.WithClientErrorLevel(slog.LevelInfo),
gin_slog.WithServerErrorLevel(slog.LevelInfo),
))
templ := template.Must(template.New("").ParseFS(templates.TemplateFiles, "html/*.tmpl"))
router.SetHTMLTemplate(templ)
router.StaticFS("/public", http.FS(assets.StaticFiles))
// Add CORS middleware for frontend access
// router.Use(middleware.CorsMiddleware)
router.Use(gin.LoggerWithConfig(gin.LoggerConfig{
SkipPaths: []string{"/health", "/metrics"},
}))
// Add recovery middleware
router.Use(gin.Recovery())
router.Use(sessions.Sessions("session", cookie.NewStore(globals.Secret)))
// Setup api routes
api := routes.SetupApiRoutes(router)
api.Use(middleware.CorsMiddleware)
routes.SetupMediaRoutes(api)
routes.SetupComicRoutes(api)
// Setup public Webapp routes
public := router.Group("/")
@@ -66,23 +71,16 @@ func main() {
protected.Use(middleware.AuthRequired)
routes.ProtectedRoutes(protected)
// Health check endpoint
router.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "healthy",
})
})
// Start server
port := os.Getenv("PORT")
if port == "" {
port = "8550"
}
log.Printf("Server starting on port %s", port)
slog.Info("Server starting", "port", port)
if err := router.Run(":" + port); err != nil {
log.Fatal("Failed to start server:", err)
}
log.Println("Kontor finished")
slog.Info("Kontor finished")
}