add-middleware
Skill36 starsChanged 4 months agoMITView on GitHub
Add a new Express middleware to this project and wire it up correctly. Use when the user asks to add middleware — rate limiting, request guards, validation, logging enrichment, custom auth checks, etc.
- Reads credentials
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 6
When the user asks to add middleware, follow these steps.
- Very specific: line 13
Use the Pino logger from src/config/logger.ts if logging is needed — never console.*.
- Very specific: line 14
Use config values from src/config/env.ts — never process.env directly.
- Very specific: line 16
No floating promises — always await or .catch().
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When the user asks to add middleware, follow these steps.
Step 1 — Create the file (src/middleware/<name>.middleware.ts)
Rules:
- Export named functions, not default exports — consistent with the barrel pattern.
- Type
req,res,nextasRequest,Response,NextFunctionfromexpress. Noany. - Use the Pino logger from
src/config/logger.tsif logging is needed — neverconsole.*. - Use config values from
src/config/env.ts— neverprocess.envdirectly. - Throw from
src/errors/for error conditions and callnext(error)— neverres.status().json()directly. - No floating promises — always
awaitor.catch().
Auth guard pattern:
import type { Request, Response, NextFunction } from 'express';
import { AuthenticationError } from '../errors';
export const requireAdmin = (req: Request, _res: Response, next: NextFunction): void => {
if (!req.user || req.user.role !== 'admin') {
return next(new AuthenticationError('Admin access required'));
}
next();
};Async middleware pattern:
import type { Request, Response, NextFunction } from 'express';
import { NotFoundError } from '../errors';
import logger from '../config/logger';
export const someAsyncGuard = async (req: Request, _res: Response, next: NextFunction): Promise<void> => {
try {
// async work
next();
} catch (error) {
logger.error(error, 'someAsyncGuard failed');
next(error);
}
};Rate limiter pattern (if adding a new limiter):
import rateLimit from 'express-rate-limit';
export const myLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
standardHeaders: true,
legacyHeaders: false,
message: { success: false, message: 'Too many requests' },
});Step 2 — Export from the barrel (src/middleware/index.ts)
export { myMiddleware } from './<name>.middleware';Step 3 — Apply it
App-wide (applies to every request) — add to src/app.ts in the correct position in the middleware chain. Order matters:
correlation → httpLogger → helmet → cors → json → cookie-parser → CSRF → [your middleware] → routesRoute-group-wide — add to the route constructor in src/routes/<name>.route.ts:
protected initializeRoutes(): void {
this.router.use(myMiddleware);
// then individual route definitions
}Per-endpoint — add inline in the route definition:
this.router.post('/', limiter, protect, myMiddleware, createValidation, this.controller.createItem);Step 4 — Verify
pnpm full-checkFix every TypeScript and lint error before reporting done.
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- NVIDIA/NeMo-Relay★ 224same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/architecture.mdcCursor rule
- .cursor/rules/conventions.mdcCursor rule
- add-openapi-docsSkill
- add-testSkill
- api-design-principlesSkill
- find-skillsSkill
- improveSkill
- multi-stage-dockerfileSkill
- new-resourceSkill
- nodejs-best-practicesSkill
- prisma-client-apiSkill
- prisma-database-setupSkill
- prisma-postgresSkill
- security-auditSkill
- typescript-magicianSkill
- update-schemaSkill
- vitestSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

