Skip to main content

DefaultHandler

@h4ad/serverless-adapter > DefaultHandler

(class) DefaultHandler

The class that implements a default serverless handler consisting of a function with event, context and callback parameters respectively

Signature:

export declare class DefaultHandler<TApp, TEvent, TContext, TCallback, TResponse, TReturn> extends BaseHandler<TApp, TEvent, TContext, TCallback, TResponse, TReturn> 

Extends: BaseHandler <TApp, TEvent, TContext, TCallback, TResponse, TReturn>

(method) forwardRequestToFramework

The function to forward the event to the framework

Signature:

protected forwardRequestToFramework(app: TApp, framework: FrameworkContract<TApp>, event: TEvent, context: TContext, adapter: AdapterContract<TEvent, TContext, TResponse>, binarySettings: BinarySettings, log: ILogger): Promise<TResponse>;

Parameters

ParameterTypeDescription
appTAppThe instance of the app (express, hapi, etc...)
frameworkFrameworkContract <TApp>The framework that will process requests
eventTEventThe event sent by serverless
contextTContextThe context sent by serverless
adapterAdapterContract <TEvent, TContext, TResponse>The adapter resolved to this event
binarySettingsBinarySettingsThe binary settings
logILoggerThe instance of logger

Returns:

Promise<TResponse>

(method) forwardResponse

The function to forward the response back to the serverless

Signature:

protected forwardResponse(event: TEvent, response: ServerlessResponse, adapter: AdapterContract<TEvent, TContext, TResponse>, binarySettings: BinarySettings, log: ILogger): TResponse;

Parameters

ParameterTypeDescription
eventTEventThe event sent by serverless
responseServerlessResponseThe response of the framework
adapterAdapterContract <TEvent, TContext, TResponse>The adapter resolved to this event
binarySettingsBinarySettingsThe binary settings
logILoggerThe instance of logger

Returns:

TResponse

(method) getHandler

Signature:

getHandler(app: TApp, framework: FrameworkContract<TApp>, adapters: AdapterContract<TEvent, TContext, TResponse>[], resolverFactory: ResolverContract<TEvent, TContext, TCallback, TResponse, TReturn>, binarySettings: BinarySettings, respondWithErrors: boolean, log: ILogger): ServerlessHandler<TReturn>;

Parameters

ParameterTypeDescription
appTApp
frameworkFrameworkContract <TApp>
adaptersAdapterContract <TEvent, TContext, TResponse>[]
resolverFactoryResolverContract <TEvent, TContext, TCallback, TResponse, TReturn>
binarySettingsBinarySettings
respondWithErrorsboolean
logILogger

Returns:

ServerlessHandler <TReturn>

(method) onForwardResponse

The hook executed before sending response to the serverless

Signature:

protected onForwardResponse(log: ILogger, statusCode: number, body: string, headers: SingleValueHeaders, isBase64Encoded: boolean): void;

Parameters

ParameterTypeDescription
logILoggerThe instance of logger
statusCodenumberThe status code of the response
bodystringThe body of the response
headersSingleValueHeadersThe headers of the response
isBase64EncodedbooleanIndicates whether the response was encoded as binary or not

Returns:

void

(method) onForwardResponseAdapterResponse

The hook executed before sending response to the serverless with response from adapter

Signature:

protected onForwardResponseAdapterResponse(log: ILogger, successResponse: TResponse, body: string): void;

Parameters

ParameterTypeDescription
logILoggerThe instance of logger
successResponseTResponseThe success response resolved by the adapter
bodystringThe body of the response sent by the framework

Returns:

void

(method) onReceiveRequest

The hook executed on receive a request, before the request is being processed

Signature:

protected onReceiveRequest(log: ILogger, event: TEvent, context: TContext, binarySettings: BinarySettings, respondWithErrors: boolean): void;

Parameters

ParameterTypeDescription
logILoggerThe instance of logger
eventTEventThe event sent by serverless
contextTContextThe context sent by serverless
binarySettingsBinarySettingsThe binary settings
respondWithErrorsbooleanIndicates whether the error stack should be included in the response or not

Returns:

void

(method) onResolveAdapter

The hook executed after resolve the adapter that will be used to handle the request and response

Signature:

protected onResolveAdapter(log: ILogger, adapter: AdapterContract<TEvent, TContext, TResponse>): void;

Parameters

ParameterTypeDescription
logILoggerThe instance of logger
adapterAdapterContract <TEvent, TContext, TResponse>The adapter resolved

Returns:

void

(method) onResolveForwardedResponseToFramework

The hook executed after handling the response sent by the framework

Signature:

protected onResolveForwardedResponseToFramework(log: ILogger, response: ServerlessResponse): void;

Parameters

ParameterTypeDescription
logILoggerThe instance of logger
responseServerlessResponseThe response sent by the framework

Returns:

void

(method) onResolveRequestValues

The hook executed after resolves the request values that will be sent to the framework

Signature:

protected onResolveRequestValues(log: ILogger, requestValues: AdapterRequest): void;

Parameters

ParameterTypeDescription
logILoggerThe instance of logger
requestValuesAdapterRequestThe request values returned by the adapter

Returns:

void