Currently, the middlewares export in endpoint files only accepts string identifiers, but it would be more flexible to allow direct middleware functions as well.
Current behavior
export const middlewares = ['dataValidation']; // Only string identifiers work
Proposed behavior
export const middlewares = [
'dataValidation', // String identifier
customMiddlewareFunction, // Direct middleware function
async (ctx, next) => {...} // Inline middleware
];
Implementation Notes
- Update middleware type definition to union of string | Middleware
- Modify middleware loader to handle both types
- Add type checking for valid middleware functions
- Update documentation with new examples
Breaking Changes
None - this is a backwards compatible enhancement
Example Use Case
const loggerMiddleware: Middleware = async (ctx, next) => {
console.log(`${ctx.req.method} ${ctx.req.url}`);
await next();
};
export const middlewares = ['dataValidation', loggerMiddleware];
Currently, the
middlewaresexport in endpoint files only accepts string identifiers, but it would be more flexible to allow direct middleware functions as well.Current behavior
Proposed behavior
Implementation Notes
Breaking Changes
None - this is a backwards compatible enhancement
Example Use Case