Guide
Essentials
- Installation
- Introduction
- Context
- Payloads
Command Line
- CLI
- Initialize
- Generate
Directory Structure
- Tree
- Authentication
- Authorization
- Context
- Handlers
- Internal
- Middleware
- Models
Design File
- design.json
Models
- Models
Concerns
- Concerns
Examples
- TODO's
Meta
- Meet the Team
Middleware
Middleware are the first functions evaluated in the request chain, before payload validation. This means that payloads are not available on middleware.
my-first-api
│ ...
│
│
│
│
│
└src
│
│
└middleware
│ │ app.ts
│ │
│ └{service}
│ │ │
│ │ └{action}
│ │ │ │ index.ts
│ │ │
│ │ └{...}
│ │
│ └{...}
│
└...
Two types of middleware are available: app-wide middleware that will be run on each request, and action specific middleware.
Application Middleware
Application middleware are mounted to each endpoint and are run on each request. An example is given, below.
import { Request, Response, NextFunction } from 'express';
export default (req: Request, res: Response, next: NextFunction): void => {
next();
}
Action Middleware
Action specific middleware are only run when that specific action’s endpoint are called. An example is given, below:
import { Request, Response, NextFunction } from 'express';
export default (req: Request, res: Response, next: NextFunction): void => {
next();
}
Caught a mistake or want to contribute to the documentation?
Edit this page on GitHub!