{"id":27351898,"url":"https://github.com/byeze/middlewares-serverless","last_synced_at":"2025-06-11T15:11:02.551Z","repository":{"id":286527146,"uuid":"961669446","full_name":"byeze/middlewares-serverless","owner":"byeze","description":"A utility for managing middleware in AWS Lambda functions. This project allows you to easily add before, after, error, and finally hooks to your Lambda handlers, enabling modular and reusable functionality across multiple Lambda functions.","archived":false,"fork":false,"pushed_at":"2025-04-07T01:19:53.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T20:54:05.942Z","etag":null,"topics":["api","aws","aws-lambda","serverless"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/byeze.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-07T01:13:11.000Z","updated_at":"2025-04-08T14:40:24.000Z","dependencies_parsed_at":"2025-04-12T20:54:05.939Z","dependency_job_id":null,"html_url":"https://github.com/byeze/middlewares-serverless","commit_stats":null,"previous_names":["byeze/middlewares-serverless"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/byeze/middlewares-serverless","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byeze%2Fmiddlewares-serverless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byeze%2Fmiddlewares-serverless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byeze%2Fmiddlewares-serverless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byeze%2Fmiddlewares-serverless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byeze","download_url":"https://codeload.github.com/byeze/middlewares-serverless/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byeze%2Fmiddlewares-serverless/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259288214,"owners_count":22834887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","aws","aws-lambda","serverless"],"created_at":"2025-04-12T20:54:05.334Z","updated_at":"2025-06-11T15:11:02.535Z","avatar_url":"https://github.com/byeze.png","language":"TypeScript","readme":"# Middlewares Serverless\n\n## Project Purpose\n\nThe purpose of this project is to provide a utility for managing middleware in AWS Lambda functions. This utility allows you to easily add before, after, error, and finally hooks to your Lambda handlers, enabling you to modularize and reuse common functionality across multiple Lambda functions.\n\n## Features\n\n- **Middleware Management**: Easily add and manage middleware hooks for before, after, error, and finally stages of Lambda execution.\n- **Error Handling**: Centralized error handling middleware to manage and format errors consistently.\n- **CORS Support**: Middleware to automatically add CORS headers to responses.\n- **JSON Body Transformation**: Middleware to parse JSON bodies of incoming requests.\n- **Modular and Reusable**: Middleware hooks can be reused across different Lambda functions.\n\n## Usage Instructions\n\n### Installation\n\nTo use this middleware utility in your project, you need to install the necessary dependencies. Assuming you have a Node.js project set up, you can install the dependencies using npm or yarn:\n\n```bash\nnpm install\n# or\nyarn install\n```\n\n### Setup\n\n1. **Create Middleware Hooks**: Define your middleware hooks in separate files. For example, you can create an error handler, CORS middleware, and JSON body transformer as shown in the provided code.\n\n2. **Initialize Middleware Utility**: Use the `MiddlewareUtil` class to register your middleware hooks and wrap your Lambda handler.\n\n### Example\n\nHere is an example of how to use the middleware utility in your Lambda function:\n\n```ts\nimport { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from \"aws-lambda\";\nimport MiddlewareUtil from \"./middlewares-serverless\";\nimport corsMiddleware from \"./middlewares-serverless/cors.middleware\";\nimport errorHandler from \"./middlewares-serverless/errorHandler.middleware\";\nimport jsonBodyTransformer from \"./middlewares-serverless/jsonBodyTransformer.middleware\";\n\n// Define your Lambda handler\nconst myLambdaHandler = async (\n  event: APIGatewayProxyEvent,\n  context: Context\n): Promise\u003cAPIGatewayProxyResult\u003e =\u003e {\n  // Your handler logic here\n  return {\n    statusCode: 200,\n    body: JSON.stringify({ message: \"Hello, world!\" }),\n  };\n};\n\n// Initialize middleware utility\nconst middleware = new MiddlewareUtil();\nmiddleware.useBefore(jsonBodyTransformer);\nmiddleware.useFinally(corsMiddleware);\nmiddleware.useOnError(errorHandler);\n\n// Wrap your handler with middleware\nexport const handler = middleware.handler(myLambdaHandler);\n```\n\n### License\n\nThis project is licensed under the Apache License, Version 2.0. See the [LICENSE](./LICENSE) file for more details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyeze%2Fmiddlewares-serverless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyeze%2Fmiddlewares-serverless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyeze%2Fmiddlewares-serverless/lists"}