Monolith Routing and Middleware
Use this skill when
- •Adding new HTTP endpoints.
- •Inserting request/response middleware.
- •Troubleshooting request flow issues.
Routing fundamentals
- •Main router is
http.ServeMuxinapp/routes/routes.go. - •Routes are registered in
registerRoutes. - •Pattern format uses method + path (e.g.,
"GET /widgets/{id}").
Middleware fundamentals
- •Middleware registration order lives in
app/middleware/registration.go. - •Current baseline includes logging and CSRF middleware.
- •Middleware wraps mux globally through
InitServerHandler.
Adding middleware safely
- •Implement
func(http.Handler) http.Handlerinapp/middleware/. - •Add it to registration slice in desired order.
- •Ensure it is side-effect free and deterministic.
- •Add tests similar to existing middleware tests.
CSRF behavior
CSRFMiddleware leverages Go's cross-origin protections; keep it in the stack unless you intentionally disable protection for a specific reason.