UNPKG

cdk-nextjs

Version:

Deploy Next.js apps on AWS with CDK

72 lines (71 loc) 2.61 kB
import { RestApi, MethodOptions, RestApiProps, AwsIntegrationProps, LambdaIntegrationOptions } from "aws-cdk-lib/aws-apigateway"; import { IVpc } from "aws-cdk-lib/aws-ec2"; import { IFunction } from "aws-cdk-lib/aws-lambda"; import { IBucket } from "aws-cdk-lib/aws-s3"; import { Construct } from "constructs"; import { PublicDirEntry } from "./nextjs-build/nextjs-build"; export interface NextjsApiOverrides { readonly restApiProps?: RestApiProps; readonly staticIntegrationProps?: AwsIntegrationProps; readonly s3MethodOptions?: MethodOptions; readonly dynamicIntegrationProps?: LambdaIntegrationOptions; } export interface NextjsApiProps { /** * Optional base path for the application */ readonly basePath?: string; /** * Override props for every construct. */ readonly overrides?: NextjsApiOverrides; /** * Path to directory of Next.js app's public directory. Used to add resources * to API Gateway REST API for public directory to go directly to S3. */ readonly publicDirEntries: PublicDirEntry[]; /** * Required if `NextjsRegionalFunctions`. The Lambda function for server-side rendering */ readonly serverFunction?: IFunction; /** * The S3 bucket containing static assets */ readonly staticAssetsBucket: IBucket; /** * [Future] Required if `NextjsRegionalContainers`. VPC to create VPC Link and ECS Service Discovery */ readonly vpc?: IVpc; } /** * Creates an API Gateway REST API for Next.js applications */ export declare class NextjsApi extends Construct { /** * The API Gateway REST API */ readonly api: RestApi; private readonly baseResource; private readonly props; private staticIntegrationRole; constructor(scope: Construct, id: string, props: NextjsApiProps); private validateProps; private createRestApi; /** * Create base resource path if needed. Important if `basePath` is set. */ private createBaseResource; private createStaticIntegrationRole; private createStaticIntegrations; /** * Maps API request to S3 request. * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/rest-api-parameter-mapping-sources.html * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html#api-items-in-folder-as-s3-objects-in-bucket */ private createS3Integration; private getStaticMethodOptions; /** * Create Lambda Proxy integration for all other routes */ private createDynamicIntegration; }