Skip to main content

Customizing

With the instance of adapter, we have some options:

setHandler

Calling this method more than once throws an error.

Defines the handler that will get the event, context and callback and pass it to the adapter and framework.

tip

See supported handlers in Handlers Section)

setResolver

Calling this method more than once throws an error.

Defines the resolver that aims to resolve the response to serverless and stop its execution when the request ends.

tip

See supported resolvers in Resolvers Section)

setFramework

Calling this method more than once throws an error.

Defines the framework that will process requests.

tip

See supported frameworks in Frameworks Section)

setLogger

Defines the logger service used during the execution of the handler

tip

To know how to implement, see the Logger Interface in API section.

setBinarySettings

Defines the binary settings for whether the response should be treated as binary or not.

When you call this method, you need to pass the interface BinarySettings, and you have two options:

  • Send an function called isBinary to verify looking inside the headers if the response should be treated as binary.
  • Or send the specific contentTypes and contentEncodings that should be treated as binary.

After that, your adapter needs to handle the binary data, it will deal correctly because they know which responses are encoded in binary.

Not every adapter deals with binary but if you used adapters like ApiGatewayV1 or ApiGatewayV2, you should be aware of this configuration.

By default, the library already handles some common cases like DEFAULT_BINARY_CONTENT_TYPES for contentTypes and DEFAULT_BINARY_ENCODINGS for contentEncodings.

setRespondWithErrors

Defines the responseWithErrors, a property that indicates whether the error stack should be included in the response or not

The errors this option will usually handle are errors during forwarding to your framework, eg: when your framework throws error 500 from a middleware error.

By default, this option will be true only when the NODE_ENV is equal to development.

addAdapter

Add an adapter to the adapters list to handle the event coming from any serverless event source.

You can call this method multiple times to add support for whatever event source you want.

tip

To know which adapters you can use, see the Adapters) section.