UNPKG

cdk-nextjs

Version:

Deploy Next.js apps on AWS with CDK

102 lines (101 loc) 4.6 kB
import { ICertificate } from "aws-cdk-lib/aws-certificatemanager"; import { AddBehaviorOptions, CachePolicyProps, Distribution, ResponseHeadersPolicyProps } from "aws-cdk-lib/aws-cloudfront"; import { FunctionUrlOriginWithOACProps, VpcOriginWithEndpointProps } from "aws-cdk-lib/aws-cloudfront-origins"; import { ApplicationLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2"; import { IFunctionUrl } from "aws-cdk-lib/aws-lambda"; import { IBucket } from "aws-cdk-lib/aws-s3"; import { Construct } from "constructs"; import { NextjsType } from "./constants"; import { OptionalDistributionProps } from "./generated-structs/OptionalDistributionProps"; import { OptionalS3OriginBucketWithOACProps } from "./generated-structs/OptionalS3OriginBucketWithOACProps"; import { PublicDirEntry } from "./nextjs-build/nextjs-build"; export interface NextjsDistributionOverrides { readonly distributionProps?: OptionalDistributionProps; readonly imageBehaviorOptions?: AddBehaviorOptions; readonly imageCachePolicyProps?: CachePolicyProps; readonly imageResponseHeadersPolicyProps?: ResponseHeadersPolicyProps; readonly dynamicBehaviorOptions?: AddBehaviorOptions; readonly dynamicCachePolicyProps?: CachePolicyProps; readonly dynamicResponseHeadersPolicyProps?: ResponseHeadersPolicyProps; readonly dynamicFunctionUrlOriginWithOACProps?: FunctionUrlOriginWithOACProps; readonly dynamicVpcOriginWithEndpointProps?: VpcOriginWithEndpointProps; readonly staticBehaviorOptions?: AddBehaviorOptions; readonly staticResponseHeadersPolicyProps?: ResponseHeadersPolicyProps; readonly s3BucketOriginProps?: OptionalS3OriginBucketWithOACProps; } export interface NextjsDistributionProps { /** * Bucket containing static assets. * Must be provided if you want to serve static files. */ readonly assetsBucket: IBucket; readonly basePath?: string; /** * Optional but only applicable for `NextjsType.GLOBAL_CONTAINERS` */ readonly certificate?: ICertificate; readonly distribution?: Distribution; /** * Required if `NextjsType.GLOBAL_FUNCTIONS` */ readonly functionUrl?: IFunctionUrl; /** * Required if `NextjsType.GLOBAL_CONTAINERS` or `NextjsType.REGIONAL_CONTAINERS` */ readonly loadBalancer?: ApplicationLoadBalancer; readonly nextjsType: NextjsType; /** * Override props for every construct. */ readonly overrides?: NextjsDistributionOverrides; /** * Entries (files/directories) within Next.js app's public directory. Used to * add static behaviors to distribution. */ readonly publicDirEntries: PublicDirEntry[]; } export declare class NextjsDistribution extends Construct { distribution: Distribution; private props; /** * Common security headers applied by default to all origins * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html#managed-response-headers-policies-security */ private commonSecurityHeadersBehavior; private staticOrigin; private dynamicOrigin; private dynamicOriginResponsePolicy; private dynamicCloudFrontFunctionAssociations; private isFunctionCompute; private staticBehaviorOptions; private dynamicBehaviorOptions; private imageBehaviorOptions; constructor(scope: Construct, id: string, props: NextjsDistributionProps); private createStaticOrigin; private createDynamicOrigin; /** * Lambda Function URLs "expect the `Host` header to contain the origin domain * name, not the domain name of the CloudFront distribution." * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer-except-host-header */ private createDynamicOriginRequestPolicy; /** * Ensures Next.js `request.url` will be correct domain instead of URL of * compute (Lambda or Fargate) * @see https://open-next.js.org/advanced/workaround#workaround-set-x-forwarded-host-header-aws-specific */ private createDynamicCloudFrontFunctionAssociations; private createStaticBehaviorOptions; private createDynamicBehaviorOptions; private createImageBehaviorOptions; /** * Creates or uses user specified CloudFront Distribution */ private getDistribution; private addDynamicBehaviors; private addStaticBehaviors; /** * Optionally prepends base path to given path pattern. */ private getPathPattern; }