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
Parameter | Type | Description |
---|---|---|
options | RequestLambdaEdgeAdapterOptions | 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
Parameter | Type | Description |
---|---|---|
event | unknown |
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
Parameter | Type | Description |
---|---|---|
cloudFrontRequest | CloudFrontRequest | The cloudfront request |
Returns:
(method) getHeadersForCloudfrontResponse
Returns headers in Cloudfront Response format.
Signature:
protected getHeadersForCloudfrontResponse(originalHeaders: BothValueHeaders): CloudFrontHeaders;
Parameters
Parameter | Type | Description |
---|---|---|
originalHeaders | BothValueHeaders | The original version of the request sent by the framework |
Returns:
CloudFrontHeaders
(method) getRequest
Signature:
getRequest(event: CloudFrontRequestEvent): AdapterRequest;
Parameters
Parameter | Type | Description |
---|---|---|
event | CloudFrontRequestEvent |
Returns:
(method) getResponse
Signature:
getResponse(\{ body, headers: frameworkHeaders, isBase64Encoded, statusCode, log, event, }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontResultResponse;
Parameters
Parameter | Type | Description |
---|---|---|
{ 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
Parameter | Type | Description |
---|---|---|
{ 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
Parameter | Type | Description |
---|---|---|
headerKey | string | The header that will be tested |
Returns:
boolean
(property) stripPathFn
Strip base path function
Signature:
protected readonly stripPathFn: StripBasePathFn;