Type alias FejMiddlewareFunction

FejMiddlewareFunction: ((ctx, next) => Promise<void> | void)

Middleware function type (Koa-style onion model)

Middleware functions receive a context object and a next function. They can execute code before calling next() (request phase) and after (response phase).

Type declaration

    • (ctx, next): Promise<void> | void
    • Parameters

      • ctx: FejContext

        The request context

      • next: (() => Promise<void>)

        Function to call the next middleware in the chain

          • (): Promise<void>
          • Returns Promise<void>

      Returns Promise<void> | void

Returns

Promise or void

Example

const myMiddleware: FejMiddlewareFunction = async (ctx, next) => {
// Before request
console.log('→ Request starting');

await next(); // Execute request and downstream middleware

// After request
console.log('← Request completed');
};