{"id":27165938,"url":"https://github.com/tepez/hapi-lambda-handler","last_synced_at":"2025-04-09T03:37:14.445Z","repository":{"id":42358363,"uuid":"113986372","full_name":"tepez/hapi-lambda-handler","owner":"tepez","description":"Run Hapi server on AWS Lambda","archived":false,"fork":false,"pushed_at":"2023-01-07T21:23:40.000Z","size":1625,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T23:19:37.336Z","etag":null,"topics":["aws-lambda","hapijs","serverless"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tepez.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-12T12:15:09.000Z","updated_at":"2021-10-03T19:23:55.000Z","dependencies_parsed_at":"2023-02-08T02:01:04.295Z","dependency_job_id":null,"html_url":"https://github.com/tepez/hapi-lambda-handler","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tepez%2Fhapi-lambda-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tepez%2Fhapi-lambda-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tepez%2Fhapi-lambda-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tepez%2Fhapi-lambda-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tepez","download_url":"https://codeload.github.com/tepez/hapi-lambda-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974610,"owners_count":21026742,"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":["aws-lambda","hapijs","serverless"],"created_at":"2025-04-09T03:37:13.858Z","updated_at":"2025-04-09T03:37:14.431Z","avatar_url":"https://github.com/tepez.png","language":"TypeScript","readme":"# hapi-lambda-handler\n\u003e Run Hapi server on AWS Lambda\n\n[![npm version](https://badge.fury.io/js/%40tepez%2Fhapi-lambda-handler.svg)](https://badge.fury.io/js/%40tepez%2Fhapi-lambda-handler)\n[![Build Status](https://secure.travis-ci.org/tepez/hapi-lambda-handler.svg?branch=master)](http://travis-ci.org/tepez/hapi-lambda-handler)\n\n## Install\n\n```\nnpm install --save @tepez/hapi-lambda-handler\n```\n\n## Usage\n\n```\n// handler.js\nconst HapiLambdaHandler = require('@tepez/hapi-lambda-handler');\nconst Hapi = require('hapi');\n\ncosnt server = new Hapi.Server();\nserver.connection({});\nserver.route({\n    method: 'GET',\n    path: '/health',\n    handler: (request, reply) =\u003e reply({ status: 'ok' })\n});\n\nexports.handler = HapiLambdaHandler.handlerFromServer(server);\n```\n\n## API\n\n### `handlerFromServer(server, [injectOptions])`\nReturn a Lambda Proxy handler function that handles event, context and callback as passed by a lambda-proxy integration of AWS Api Gateway.\n\n- `server`:\n  The Hapi server or a promise to it if it has to be initialized first.\n\n  It is the **responsibility** of the using package to report initialization errors in the server.\n  If the promise to the server rejects, 500 errors will be returned for every request.\n\n- `injectOptions`:\n    - `basePath: string`\n\n      If the API is deployed under a [custom path mapping](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-basepathmapping.html)\n      this should be the basePath, e.g. '/v1.0'.\n\n    - `modifyRequest: (event: APIGatewayEvent, context: Context, request: ServerInjectOptions) =\u003e void`\n\n      A synchronous callback receiving the `event`, the `context` and the `request` just before injecting it to the Hapi server.\n      This is a chance to modify the request in-place, e.g. to apply credentials to it.\n\n## Request tail\n\nSometimes we need to wait for some processes to finish before returning the response\nto APIGateway, e.g. report an error to Sentry.\n\nHapi 17 [dropped support](https://github.com/hapijs/hapi/issues/3658) for request tails,\nwhich was the method we used before.\n\nYou can create an array of promises on `request.app.tailPromises`, the handler will\nwait for them with `Promise.all()` before returning the response.\n\n```typescript\nfunction handler(request: IRequestWithTailPromises) =\u003e {\n    // ...\n    if (!request.app.tailPromises) request.app.tailPromises = [];\n    request.app.tailPromises.push(somePromise);\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftepez%2Fhapi-lambda-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftepez%2Fhapi-lambda-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftepez%2Fhapi-lambda-handler/lists"}