generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 175
Closed
Labels
completedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utility
Milestone
Description
Use case
Users should be able to add middleware to specific routes that are ran after any global middlewares have ran.
Solution/User Experience
Register middleware
Middleware for routes is added as an argument to the HTTP verb methods exposed by the router:
const middleware1 = async (params, options, next) => {
console.log('middleware1-start');
await next();
console.log('middleware1-end');
};
const middleware2 = async (params, options, next) => {
console.log('middleware2-start');
await next();
console.log('middleware2-end');
};
const middleware3 = async (params, options, next) => {
console.log('middleware3-start');
await next();
console.log('middleware3-end');
};
app.use(middleware1);
app.get('/global', [], async () => {
console.log('handler');
return { success: true };
});
app.get('/route-specific', [middleware2, middleware3], async () => {
console.log('handler');
return { success: true };
});
await app.resolve(createTestEvent('/global', 'GET'), context);
/** prints
'middleware1-start',
'handler',
'middleware1-end',
**/
await app.resolve(createTestEvent('/route-specific', 'GET'), context);
/** prints
'middleware1-start',
'middleware2-start',
'middleware3-start',
'handler',
'middleware3-end',
'middleware2-end',
'middleware1-end',
**/
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
completedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utility
Type
Projects
Status
Shipped