updates
This commit is contained in:
@@ -3,12 +3,15 @@ package routes
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
handlers "go-server/internal/handlers"
|
||||
"go-server/internal/middleware"
|
||||
"go-server/internal/repository"
|
||||
"go-server/internal/service"
|
||||
"go-server/internal/templates"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -36,9 +39,28 @@ func SetupRouter(db *gorm.DB) *gin.Engine {
|
||||
r.Use(middleware.Logger())
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
// Serve simple text at "/"
|
||||
// Cache headers for static files
|
||||
r.Use(func(c *gin.Context) {
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/static/") || c.Request.URL.Path == "/favicon.ico" {
|
||||
c.Header("Cache-Control", "public, max-age=31536000")
|
||||
}
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Serve static files
|
||||
r.Static("/static", "./static")
|
||||
r.StaticFile("/favicon.ico", "./static/favicon.ico")
|
||||
|
||||
// Serve home page
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusOK, "Hello")
|
||||
ctx := templ.WithChildren(c.Request.Context(), templates.Home())
|
||||
templates.Layout("Home").Render(ctx, c.Writer)
|
||||
})
|
||||
|
||||
// Serve login page
|
||||
r.GET("/login", func(c *gin.Context) {
|
||||
ctx := templ.WithChildren(c.Request.Context(), templates.Login())
|
||||
templates.Layout("Login").Render(ctx, c.Writer)
|
||||
})
|
||||
|
||||
// Custom 404 handler
|
||||
@@ -69,6 +91,7 @@ func SetupRouter(db *gorm.DB) *gin.Engine {
|
||||
dailyOverviewController := handlers.NewDailyOverviewController(dailyOverviewService)
|
||||
categoryController := handlers.NewCategoryController(categoryService)
|
||||
todoController := handlers.NewTodoController(todoService)
|
||||
loginHandler := handlers.NewLoginHandler()
|
||||
|
||||
skipAuth := true
|
||||
|
||||
@@ -119,6 +142,11 @@ func SetupRouter(db *gorm.DB) *gin.Engine {
|
||||
{"GET", "/weekly", todoController.GetWeeklySummary, !skipAuth}, // Get weekly summary
|
||||
},
|
||||
},
|
||||
"user": {
|
||||
Routes: []Route{
|
||||
{"POST", "/login", loginHandler.Login, false},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Register all routes dynamically
|
||||
|
||||
Reference in New Issue
Block a user