middleware-patterns

Explain middleware patterns for request processing across frameworks and runtimes.

35|5|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/Kinfe123/fm-skills --skill middleware-patterns-kinfe123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middleware-patterns
Source: https://github.com/Kinfe123/fm-skills/tree/main/middleware-patterns
Command: npx skills add https://github.com/Kinfe123/fm-skills --skill middleware-patterns-kinfe123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill explains middleware concepts and patterns to help engineers design reliable request/response pipelines that work across multiple frameworks and runtimes.

Core Features & Use Cases

  • Understanding middleware types: global, route, group, and handler middleware across server, edge, and client contexts.
  • Pipeline design: chain, pipeline, and decorator patterns for composable, testable request processing.
  • Common use cases: authentication/authorization, logging, CORS, rate limiting, and security headers.
  • Framework integration: guidance for Express, H3/Nitro, Cloudflare Workers, and framework-agnostic concepts.

Quick Start

  1. Implement a simple logging middleware that records method and path, then calls next().
  2. Add an authentication middleware that validates a token and attaches the user to the request context.
  3. Compose the middleware with a route handler and apply it to a minimal API endpoint to observe the unified request/response flow.

Frequently Asked Questions about middleware-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a middleware pipeline for authentication and logging in Node.js?

To design a middleware pipeline in Node.js, you chain composable functions where each processes the request and calls next(). This pattern handles authentication, logging, and CORS by passing control sequentially through the request lifecycle before reaching the route handler.

What is the difference between global, route, and group middleware in request processing?

Global middleware runs on every incoming request, route middleware targets specific endpoints, and group middleware applies to a collection of routes. These types dictate the scope of request processing for tasks like authorization and security headers across server and edge runtimes.

Does this middleware pattern approach work with edge runtimes like Cloudflare Workers?

Yes, the middleware pattern works with edge runtimes like Cloudflare Workers. The skill provides framework-agnostic guidance for designing request pipelines and covers specific integration examples for edge environments alongside Node.js and H3/Nitro frameworks.

What's the best way to handle errors in a composable middleware chain?

The best way to handle errors in a composable middleware chain is to use decorator or pipeline patterns that wrap the next() call. This allows centralized error catching within the request processing flow, ensuring consistent error responses across server and edge contexts.

Can I use middleware patterns for rate limiting and CORS configuration?

Yes, you can use middleware patterns for rate limiting and CORS configuration. They are common use cases for request processing pipelines, allowing you to intercept incoming requests, apply security rules, and attach headers before the primary route handler executes.