Decoupled middleware

This commit is contained in:
2024-01-24 20:07:42 -07:00
parent ee5f821b67
commit b4aba437e5
6 changed files with 8 additions and 131 deletions

View File

@ -7,9 +7,9 @@ import (
"text/template"
"goth.stack/api"
"goth.stack/middleware"
"goth.stack/pages"
bunroutermiddleware "github.com/atridadl/bunrouter.middleware"
"github.com/joho/godotenv"
"github.com/uptrace/bunrouter"
"github.com/uptrace/bunrouter/extra/reqlog"
@ -30,7 +30,7 @@ func main() {
// Initialize router
router := bunrouter.New(
bunrouter.Use(reqlog.NewMiddleware(), middleware.RequestID, middleware.SecureHeaders),
bunrouter.Use(reqlog.NewMiddleware(), bunroutermiddleware.RequestID, bunroutermiddleware.SecureHeaders),
)
// Static server
@ -42,7 +42,7 @@ func main() {
})
// Page routes
pageGroup := router.NewGroup("", bunrouter.Use(middleware.NewRateLimiter(50).RateLimit))
pageGroup := router.NewGroup("", bunrouter.Use(bunroutermiddleware.NewRateLimiter(50).RateLimit))
pageGroup.GET("/", pages.Home)
pageGroup.GET("/blog", pages.Blog)
pageGroup.GET("/post/:post", pages.Post)