Skip to main content

RequestLambdaEdgeAdapter

@h4ad/serverless-adapter > RequestLambdaEdgeAdapter

(class) RequestLambdaEdgeAdapter

The adapter to handle requests from AWS Lambda @ Edge of the type Viewer Request.

The idea of this Adapter is to you be able to expose your framework to the Edge, like when you build for Cloudfront.

Lambda edge docs Event Reference

Signature:

export declare class RequestLambdaEdgeAdapter implements AdapterContract<CloudFrontRequestEvent, Context, CloudFrontResultResponse> 

Implements: AdapterContract <CloudFrontRequestEvent, Context, CloudFrontResultResponse>

Example

const stripBasePath = '/api'; // in case you have configure the cloudfront to forward the path /api to your lambda
const adapter = new RequestLambdaEdgeAdapter(\{ stripBasePath });

(constructor)

Default constructor

Signature:

constructor(options?: RequestLambdaEdgeAdapterOptions | undefined);

Parameters

ParameterTypeDescription
optionsRequestLambdaEdgeAdapterOptions | undefined(Optional) The options to customize the RequestLambdaEdgeAdapter

(property) cachedDisallowedHeaders

This property is used to cache the disallowed headers in RegExp version, even if you provide a string in disallowedHeader , we will cache it in an instance of RegExp .

Signature:

protected readonly cachedDisallowedHeaders: RegExp[];

(method) canHandle

Signature:

canHandle(event: unknown): event is CloudFrontRequestEvent;

Parameters

ParameterTypeDescription
eventunknown

Returns:

event is CloudFrontRequestEvent

(method) getAdapterName

Signature:

getAdapterName(): string;

Returns:

string

(method) getFlattenedHeadersFromCloudfrontRequest

Returns the headers with the flattened (non-list) values of the cloudfront request headers

Signature:

protected getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest: CloudFrontRequest): SingleValueHeaders;

Parameters

ParameterTypeDescription
cloudFrontRequestCloudFrontRequestThe cloudfront request

Returns:

SingleValueHeaders

(method) getHeadersForCloudfrontResponse

Returns headers in Cloudfront Response format.

Signature:

protected getHeadersForCloudfrontResponse(originalHeaders: BothValueHeaders): CloudFrontHeaders;

Parameters

ParameterTypeDescription
originalHeadersBothValueHeadersThe original version of the request sent by the framework

Returns:

CloudFrontHeaders

(method) getRequest

Signature:

getRequest(event: CloudFrontRequestEvent): AdapterRequest;

Parameters

ParameterTypeDescription
eventCloudFrontRequestEvent

Returns:

AdapterRequest

(method) getResponse

Signature:

getResponse(\{ body, headers: frameworkHeaders, isBase64Encoded, statusCode, log, event, }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontResultResponse;

Parameters

ParameterTypeDescription
{ body, headers: frameworkHeaders, isBase64Encoded, statusCode, log, event, }GetResponseAdapterProps <CloudFrontRequestEvent>

Returns:

CloudFrontResultResponse

(method) onErrorWhileForwarding

Signature:

onErrorWhileForwarding(\{ error, delegatedResolver, respondWithErrors, log, event, }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void;

Parameters

ParameterTypeDescription
{ error, delegatedResolver, respondWithErrors, log, event, }OnErrorProps <CloudFrontRequestEvent, CloudFrontRequestResult>

Returns:

void

(property) options

Signature:

protected readonly options?: RequestLambdaEdgeAdapterOptions | undefined;

(method) shouldStripHeader

Returns the information if we should remove the response header

Signature:

protected shouldStripHeader(headerKey: string): boolean;

Parameters

ParameterTypeDescription
headerKeystringThe header that will be tested

Returns:

boolean

(property) stripPathFn

Strip base path function

Signature:

protected readonly stripPathFn: StripBasePathFn;