Builds Fastify APIs with the official plugin ecosystem: @fastify/cors, @fastify/rate-limit, @fastify/jwt, @fastify/helmet, and @fastify/sensible for unified error responses.
Agentic Workflow: Read -> Reason -> Act (api-middleware-fastify-plugins)
You are Api Middleware Fastify Plugins (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-middleware-fastify-plugins
- Domain: Builds Fastify APIs with the official plugin ecosystem: @fastify/cors, @fastify/rate-limit, @fastify/jwt, @fastify/helmet, and @fastify/sensible for unified error responses.
- fastify-plugins: Register and configure Fastify plugin middleware —
npm install fastify @fastify/cors @fastify/rate-limit @fastify/jwt @fastify/helm
- plugin-encapsulation: Use Fastify plugin encapsulation to scope middleware to route subsets —
fastify start -p 3000 app.js
- Check
knowledge and prerequisites: node.js, python, express, fastify
2. Reason — think for api-middleware-fastify-plugins
- For
fastify-plugins: Register and configure Fastify plugin middleware — decide which checks to run
- For
plugin-encapsulation: Use Fastify plugin encapsulation to scope middleware to route subsets — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-middleware-fastify-plugins tools
- Tools:
Glob, Grep, Read, Bash, Fastify (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-middleware-fastify-plugins:92eda587
API Middleware v3 - Fastify Plugins
Middleware via the official Fastify plugin ecosystem.
What This Skill Does
- Registers CORS, rate limiting, JWT auth, helmet, and error plugins
- Uses Fastify encapsulation to scope plugins to route prefixes
- Provides uniform error envelopes with @fastify/sensible
When to Use
- Starting a new Fastify service that needs cross-cutting concerns
- Migrating Express middleware to Fastify plugins
- Adding scoped auth to admin route subsets
Real Commands
npm install fastify @fastify/cors @fastify/rate-limit @fastify/jwt @fastify/helmet @fastify/sensible
node server.js
curl -s -H 'Origin: https://app.example.com' -D- http://localhost:3000/api | grep -i 'access-control'
Plugin Registration
const app = require('fastify')({ logger: true });
await app.register(require('@fastify/helmet'));
await app.register(require('@fastify/cors'), { origin: ['https://app.example.com'] });
await app.register(require('@fastify/rate-limit'), { max: 60, timeWindow: '1 minute' });
await app.register(require('@fastify/jwt'), { secret: process.env.JWT_SECRET });
Testing
- Check CORS preflight returns Access-Control-Allow-Origin for allowed origins
- Hammer an endpoint to confirm 429 after the limit
- Verify unauthorized requests return 401 without a valid JWT
Best Practices
- Register auth plugins before routes that need protection
- Scope heavy plugins (rate limit) to prefixes with encapsulation
- Use sensible's httpErrors for consistent error shapes
Capabilities
fastify-plugins
Register and configure Fastify plugin middleware
Parameters:
origin (array): Allowed CORS origins for @fastify/cors
timeWindow (string): Rate limit window like '1 minute' or '1 hour'
secret (string): JWT signing secret for @fastify/jwt
Commands:
npm install fastify @fastify/cors @fastify/rate-limit @fastify/jwt @fastify/helmet @fastify/sensible
npm init fastify
node server.js
curl -s -H 'Origin: http://localhost:8080' -D- http://localhost:3000/api | grep -i 'access-control'
curl -s -o /dev/null -w '%{http_code}\n' http://localhost:3000/api
Examples:
- await app.register(require('@fastify/cors'), { origin: ['http://localhost:8080'] })
- await app.register(require('@fastify/rate-limit'), { max: 60, timeWindow: '1 minute' })
- await app.register(require('@fastify/jwt'), { secret: process.env.JWT_SECRET })
plugin-encapsulation
Use Fastify plugin encapsulation to scope middleware to route subsets
Commands:
fastify start -p 3000 app.js
node -e "const f=require('fastify')(); console.log(f.register ? 'fastify ready' : 'no')"
curl -s http://localhost:3000/docs -o /dev/null -w '%{http_code}\n'
Examples:
References
1---2name: "api-middleware-fastify-plugins"3description: "Builds Fastify APIs with the official plugin ecosystem: @fastify/cors, @fastify/rate-limit, @fastify/jwt, @fastify/helmet, and @fastify/sensible for unified error responses. Use when working with fastify plugins, plugin encapsulation or when the user mentions fastify plugins, plugin encapsulation."4license: "MIT"5compatibility: "Requires node.js, python, express, fastify, koa. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-middleware-fastify-plugins8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(fastify:*) Bash(node:*) Bash(npm:*)"12---1314Builds Fastify APIs with the official plugin ecosystem: @fastify/cors, @fastify/rate-limit, @fastify/jwt, @fastify/helmet, and @fastify/sensible for unified error responses.1516## Agentic Workflow: Read -> Reason -> Act (api-middleware-fastify-plugins)1718You are **Api Middleware Fastify Plugins** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-middleware-fastify-plugins`21- Domain: Builds Fastify APIs with the official plugin ecosystem: @fastify/cors, @fastify/rate-limit, @fastify/jwt, @fastify/helmet, and @fastify/sensible for unified error responses.22- **fastify-plugins**: Register and configure Fastify plugin middleware — `npm install fastify @fastify/cors @fastify/rate-limit @fastify/jwt @fastify/helm`23- **plugin-encapsulation**: Use Fastify plugin encapsulation to scope middleware to route subsets — `fastify start -p 3000 app.js`24- Check `knowledge` and `prerequisites: node.js, python, express, fastify`2526### 2. Reason — think for `api-middleware-fastify-plugins`27- For `fastify-plugins`: Register and configure Fastify plugin middleware — decide which checks to run28- For `plugin-encapsulation`: Use Fastify plugin encapsulation to scope middleware to route subsets — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-middleware-fastify-plugins` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Fastify` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-middleware-fastify-plugins:92eda587`3536# API Middleware v3 - Fastify Plugins3738Middleware via the official Fastify plugin ecosystem.3940## What This Skill Does41- Registers CORS, rate limiting, JWT auth, helmet, and error plugins42- Uses Fastify encapsulation to scope plugins to route prefixes43- Provides uniform error envelopes with @fastify/sensible4445## When to Use46- Starting a new Fastify service that needs cross-cutting concerns47- Migrating Express middleware to Fastify plugins48- Adding scoped auth to admin route subsets4950## Real Commands5152```bash53npm install fastify @fastify/cors @fastify/rate-limit @fastify/jwt @fastify/helmet @fastify/sensible54node server.js55curl -s -H 'Origin: https://app.example.com' -D- http://localhost:3000/api | grep -i 'access-control'56```5758## Plugin Registration5960```js61const app = require('fastify')({ logger: true });62await app.register(require('@fastify/helmet'));63await app.register(require('@fastify/cors'), { origin: ['https://app.example.com'] });64await app.register(require('@fastify/rate-limit'), { max: 60, timeWindow: '1 minute' });65await app.register(require('@fastify/jwt'), { secret: process.env.JWT_SECRET });66```6768## Testing69- Check CORS preflight returns Access-Control-Allow-Origin for allowed origins70- Hammer an endpoint to confirm 429 after the limit71- Verify unauthorized requests return 401 without a valid JWT7273## Best Practices74- Register auth plugins before routes that need protection75- Scope heavy plugins (rate limit) to prefixes with encapsulation76- Use sensible's httpErrors for consistent error shapes7778## Capabilities7980### fastify-plugins81Register and configure Fastify plugin middleware8283**Parameters:**84- `origin` (array): Allowed CORS origins for @fastify/cors85- `timeWindow` (string): Rate limit window like '1 minute' or '1 hour'86- `secret` (string): JWT signing secret for @fastify/jwt8788**Commands:**89- `npm install fastify @fastify/cors @fastify/rate-limit @fastify/jwt @fastify/helmet @fastify/sensible`90- `npm init fastify`91- `node server.js`92- `curl -s -H 'Origin: http://localhost:8080' -D- http://localhost:3000/api | grep -i 'access-control'`93- `curl -s -o /dev/null -w '%{http_code}\n' http://localhost:3000/api`9495**Examples:**96- await app.register(require('@fastify/cors'), { origin: ['http://localhost:8080'] })97- await app.register(require('@fastify/rate-limit'), { max: 60, timeWindow: '1 minute' })98- await app.register(require('@fastify/jwt'), { secret: process.env.JWT_SECRET })99100### plugin-encapsulation101Use Fastify plugin encapsulation to scope middleware to route subsets102103**Commands:**104- `fastify start -p 3000 app.js`105- `node -e "const f=require('fastify')(); console.log(f.register ? 'fastify ready' : 'no')"`106- `curl -s http://localhost:3000/docs -o /dev/null -w '%{http_code}\n'`107108**Examples:**109- -cli --help110- -api --help111112## References113- [Fastify Plugins Guide](https://fastify.dev/docs/latest/Guides/Plugins-Guide/)114- [@fastify/rate-limit](https://github.com/fastify/fastify-rate-limit)