Serverless Adapter (@h4ad/serverless-adapter)

website·Indexed 33 days ago

https://serverless-adapter.viniciusl.com.br

A library providing adapters to handle requests across various serverless environments, including AWS Application Load Balancer, Azure HttpTriggerV4, and Firebase. It includes frameworks for Apollo Server and JSON body parsing, as well as specialized handlers and contracts for managing serverless requests and responses.

Tokens
71.8K
Snippets
492
Records
721
Agent score
56%

What's inside Serverless Adapter

  1. Overview of Serverless Adapter library

    Serverless Adapter is a library designed to connect any NodeJS framework to any serverless environment. It allows developers to plug in a framework, select a handler for the specific serverless environment, and choose appropriate adapters to deploy an application.

    Supported NodeJS Frameworks: Express, Fastify, tRPC, Apollo Server, NestJS, Deepkit, Koa, and Hapi.

    Supported Serverless Environments: AWS, Azure, Google Cloud, Digital Ocean, Firebase, and Huawei.

  2. Overview of Serverless Adapter library

    Serverless Adapter is a library designed to connect any NodeJS framework to any serverless environment. It allows developers to plug in a framework, select a handler for the specific serverless environment, and choose an adapter to deploy the application.

    Supported NodeJS Frameworks: Express, Fastify, tRPC, Apollo Server, NestJS, Deepkit, Koa, and Hapi.

    Supported Serverless Environments: AWS, Azure, Google Cloud, Digital Ocean, Firebase, and Huawei.

  3. Overview of serverless-adapter

    The serverless-adapter library is a refactored version of @vendia/serverless-express designed to provide a more extensible way to interact with event sources. It uses a contract-based architecture (Frameworks, Network, Adapters, Resolvers, and Handlers) to abstract integrations between library layers. Key advantages include the ability to add new event sources via the addAdapter method without waiting for library updates and full TypeScript support.
  4. Overview of Serverless Adapter library

    Serverless Adapter is a library designed to connect any NodeJS framework to any serverless environment. It allows developers to plug in a framework, select the appropriate handler for their serverless environment, and choose adapters to deploy their application.

    Supported NodeJS frameworks include: Express, Fastify, tRPC, Apollo Server, NestJS, Deepkit, Koa, and Hapi.

    Supported serverless environments include: AWS, Azure, Google Cloud, Digital Ocean, Firebase, and Huawei.

  5. Overview of Serverless Adapter library

    Serverless Adapter is a library designed to connect any NodeJS framework to any serverless environment. It allows developers to plug in a framework, select a handler for the specific serverless environment, and choose the appropriate adapters to deploy an application.

    Supported NodeJS Frameworks: Express, Fastify, tRPC, Apollo Server, NestJS, Deepkit, Koa, and Hapi.

    Supported Serverless Environments: AWS, Azure, Google Cloud, Digital Ocean, Firebase, and Huawei.

  6. Overview of the AWS SQS Adapter

    The SQS Adapter allows the serverless-adapter library to handle requests from AWS SQS. Since SQS does not use standard HTTP requests, the adapter simulates a POST request to /sqs by default, where the request body contains the SQS event property as JSON. Note that the responseWithErrors option is ignored by this adapter; it always calls resolver.fail when an error occurs.
  7. Use ServerlessResponse to manage cloud framework responses

    The ServerlessResponse class (extending ServerResponse) represents a response instance used to send data to a framework. It captures response details and waits for the framework to finish processing the request before using its properties to build the final response sent to the cloud.
    export declare class ServerlessResponse extends ServerResponse
  8. Use RawRequest to handle raw HTTP requests in serverless environments

    The RawRequest abstract class in @h4ad/serverless-adapter provides methods to extract a raw request from an Express HTTP request. This is particularly useful in environments like Firebase or GCP where Express and body-parser are used by default, which can interfere with frameworks that expect a native Node.js http module request.
    export declare abstract class RawRequest<TApp>
  9. Use DefaultNetwork to manage serverless requests and responses

    The DefaultNetwork class is the default network implementation used to create framework-specific request and response objects. It implements the NetworkContract for ServerlessRequest and ServerlessResponse types.
    import { DefaultNetwork } from '@h4ad/serverless-adapter';
    
    const network = new DefaultNetwork(options);
  10. Use ApiGatewayV2Adapter for AWS API Gateway V2

    The ApiGatewayV2Adapter is used to handle requests from AWS API Gateway V2. It implements the AdapterContract for APIGatewayProxyEventV2 and APIGatewayProxyStructuredResultV2 types.

    Caveat on Chunked Encoding: By default, this adapter throws an exception when transfer-encoding=chunked is sent, following AWS known issues. However, if you are using this adapter with a Lambda Function URL, you can support chunked encoding by changing the invocation method from BUFFERED to RESPONSE_STREAM.

    import { ApiGatewayV2Adapter } from '@h4ad/serverless-adapter';
    
    const stripBasePath = '/any/custom/base/path'; // default is ''
    const adapter = new ApiGatewayV2Adapter({ stripBasePath });
  11. Use EventBridgeAdapter to handle AWS EventBridge requests

    The EventBridgeAdapter is used to handle requests originating from AWS EventBridge (CloudWatch Events). Note that the responseWithErrors option is ignored by this adapter; it will always call resolver.fail when an error occurs.
    import { EventBridgeAdapter } from '@h4ad/serverless-adapter';
    
    const eventBridgeForwardPath = '/your/route/eventbridge'; // default /eventbridge
    const eventBridgeForwardMethod = 'POST'; // default POST
    const adapter = new EventBridgeAdapter({
      eventBridgeForwardPath,
      eventBridgeForwardMethod
    });
  12. Use HuaweiApiGatewayAdapter to handle Huawei API Gateway requests

    The HuaweiApiGatewayAdapter is a class that implements the AdapterContract to translate requests and responses between the Huawei API Gateway and a serverless application. It handles HuaweiApiGatewayEvent, HuaweiContext, and HuaweiApiGatewayResponse types.
    import { HuaweiApiGatewayAdapter } from '@h4ad/serverless-adapter';
    
    const adapter = new HuaweiApiGatewayAdapter({
      stripBasePath: '/any/custom/base/path',
    });