diff --git a/API.md b/API.md index 6cd8ba71..7bc95afd 100644 --- a/API.md +++ b/API.md @@ -206,7 +206,6 @@ Any object. | --- | --- | --- | | node | constructs.Node | The tree node. | | bucket | aws-cdk-lib.aws_s3.IBucket | Convenience method to access `Nextjs.staticAssets.bucket`. | -| tempBuildDir | string | Where build-time assets for deployment are stored. | | url | string | URL of Next.js App. | | distribution | NextjsDistribution | CloudFront distribution. | | imageOptimizationFunction | NextjsImage | The image optimization handler lambda function. | @@ -243,18 +242,6 @@ Convenience method to access `Nextjs.staticAssets.bucket`. --- -##### `tempBuildDir`Required - -```typescript -public readonly tempBuildDir: string; -``` - -- *Type:* string - -Where build-time assets for deployment are stored. - ---- - ##### `url`Required ```typescript @@ -2597,158 +2584,6 @@ Set this option if the domain is not hosted on Amazon Route 53. --- -### NextjsBaseProps - -Common props shared across NextJS-related CDK constructs. - -#### Initializer - -```typescript -import { NextjsBaseProps } from 'cdk-nextjs-standalone' - -const nextjsBaseProps: NextjsBaseProps = { ... } -``` - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| nextjsPath | string | Relative path to the directory where the NextJS project is located. | -| buildCommand | string | Optional value used to install NextJS node dependencies. | -| buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | - ---- - -##### `nextjsPath`Required - -```typescript -public readonly nextjsPath: string; -``` - -- *Type:* string - -Relative path to the directory where the NextJS project is located. - -Can be the root of your project (`.`) or a subdirectory (`packages/web`). - ---- - -##### `buildCommand`Optional - -```typescript -public readonly buildCommand: string; -``` - -- *Type:* string -- *Default:* 'npx --yes open-next@^2 build' - -Optional value used to install NextJS node dependencies. - ---- - -##### `buildPath`Optional - -```typescript -public readonly buildPath: string; -``` - -- *Type:* string - -The directory to execute `npm run build` from. - -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. - ---- - -##### `environment`Optional - -```typescript -public readonly environment: {[ key: string ]: string}; -``` - -- *Type:* {[ key: string ]: string} - -Custom environment variables to pass to the NextJS build and runtime. - ---- - -##### `projectRoot`Optional - -```typescript -public readonly projectRoot: string; -``` - -- *Type:* string - -Root of your project, if different from `nextjsPath`. - -Defaults to current working directory. - ---- - -##### `quiet`Optional - -```typescript -public readonly quiet: boolean; -``` - -- *Type:* boolean - -Less build output. - ---- - -##### `sharpLayerArn`Optional - -```typescript -public readonly sharpLayerArn: string; -``` - -- *Type:* string - -Optional arn for the sharp lambda layer. - -If omitted, the layer will be created. - ---- - -##### `skipFullInvalidation`Optional - -```typescript -public readonly skipFullInvalidation: boolean; -``` - -- *Type:* boolean - -By default all CloudFront cache will be invalidated on deployment. - -This can be set to true to skip the full cache invalidation, which -could be important for some users. - ---- - -##### `tempBuildDir`Optional - -```typescript -public readonly tempBuildDir: string; -``` - -- *Type:* string - -Directory to store temporary build files in. - -Defaults to os.tmpdir(). - ---- - ### NextjsBucketDeploymentProps #### Initializer @@ -2901,15 +2736,11 @@ const nextjsBuildProps: NextjsBuildProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| nextjsPath | string | Relative path to the directory where the NextJS project is located. | -| buildCommand | string | Optional value used to install NextJS node dependencies. | -| buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | +| nextjsPath | string | *No description.* | +| buildCommand | string | *No description.* | +| buildPath | string | *No description.* | +| environment | {[ key: string ]: string} | *No description.* | +| quiet | boolean | *No description.* | | skipBuild | boolean | *No description.* | --- @@ -2922,9 +2753,7 @@ public readonly nextjsPath: string; - *Type:* string -Relative path to the directory where the NextJS project is located. - -Can be the root of your project (`.`) or a subdirectory (`packages/web`). +> [{@link NextjsProps.nextjsPath }]({@link NextjsProps.nextjsPath }) --- @@ -2935,9 +2764,8 @@ public readonly buildCommand: string; ``` - *Type:* string -- *Default:* 'npx --yes open-next@^2 build' -Optional value used to install NextJS node dependencies. +> [{@link NextjsProps.buildCommand }]({@link NextjsProps.buildCommand }) --- @@ -2949,11 +2777,7 @@ public readonly buildPath: string; - *Type:* string -The directory to execute `npm run build` from. - -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. +> [{@link NextjsProps.buildPath }]({@link NextjsProps.buildPath }) --- @@ -2965,21 +2789,7 @@ public readonly environment: {[ key: string ]: string}; - *Type:* {[ key: string ]: string} -Custom environment variables to pass to the NextJS build and runtime. - ---- - -##### `projectRoot`Optional - -```typescript -public readonly projectRoot: string; -``` - -- *Type:* string - -Root of your project, if different from `nextjsPath`. - -Defaults to current working directory. +> [{@link NextjsProps.environment }]({@link NextjsProps.environment }) --- @@ -2991,50 +2801,7 @@ public readonly quiet: boolean; - *Type:* boolean -Less build output. - ---- - -##### `sharpLayerArn`Optional - -```typescript -public readonly sharpLayerArn: string; -``` - -- *Type:* string - -Optional arn for the sharp lambda layer. - -If omitted, the layer will be created. - ---- - -##### `skipFullInvalidation`Optional - -```typescript -public readonly skipFullInvalidation: boolean; -``` - -- *Type:* boolean - -By default all CloudFront cache will be invalidated on deployment. - -This can be set to true to skip the full cache invalidation, which -could be important for some users. - ---- - -##### `tempBuildDir`Optional - -```typescript -public readonly tempBuildDir: string; -``` - -- *Type:* string - -Directory to store temporary build files in. - -Defaults to os.tmpdir(). +> [{@link NextjsProps.quiet }]({@link NextjsProps.quiet }) --- @@ -3046,7 +2813,7 @@ public readonly skipBuild: boolean; - *Type:* boolean -> [ `NextjsProps.skipBuild`]( `NextjsProps.skipBuild`) +> [{@link NextjsProps.skipBuild }]({@link NextjsProps.skipBuild }) --- @@ -3232,272 +2999,139 @@ const nextjsDistributionProps: NextjsDistributionProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| nextjsPath | string | Relative path to the directory where the NextJS project is located. | -| buildCommand | string | Optional value used to install NextJS node dependencies. | -| buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | | imageOptFunction | aws-cdk-lib.aws_lambda.IFunction | Lambda function to optimize images. | -| nextBuild | NextjsBuild | Built NextJS app. | +| nextBuild | NextjsBuild | *No description.* | +| nextjsPath | string | *No description.* | | serverFunction | aws-cdk-lib.aws_lambda.IFunction | Lambda function to route all non-static requests to. | | staticAssetsBucket | aws-cdk-lib.aws_s3.IBucket | Bucket containing static assets. | -| basePath | string | Optional value to prefix the Next.js site under a /prefix path on CloudFront. Usually used when you deploy multiple Next.js sites on same domain using /sub-path. | +| basePath | string | *No description.* | | cachePolicies | NextjsCachePolicyProps | Override the default CloudFront cache policies created internally. | | cdk | NextjsDistributionCdkProps | Overrides for created CDK resources. | | customDomain | string \| NextjsDomainProps | The customDomain for this website. Supports domains that are hosted either on [Route 53](https://aws.amazon.com/route53/) or externally. | -| distribution | aws-cdk-lib.aws_cloudfront.Distribution | Optional CloudFront Distribution created outside of this construct that will be used to add Next.js behaviors and origins onto. Useful with `basePath`. | +| distribution | aws-cdk-lib.aws_cloudfront.Distribution | *No description.* | | functionUrlAuthType | aws-cdk-lib.aws_lambda.FunctionUrlAuthType | Override lambda function url auth type. | | originRequestPolicies | NextjsOriginRequestPolicyProps | Override the default CloudFront origin request policies created internally. | -| stackPrefix | string | Optional value to prefix the edge function stack It defaults to "Nextjs". | -| stageName | string | Include the name of your deployment stage if present. | --- -##### `nextjsPath`Required +##### `imageOptFunction`Required ```typescript -public readonly nextjsPath: string; +public readonly imageOptFunction: IFunction; ``` -- *Type:* string +- *Type:* aws-cdk-lib.aws_lambda.IFunction -Relative path to the directory where the NextJS project is located. +Lambda function to optimize images. -Can be the root of your project (`.`) or a subdirectory (`packages/web`). +Must be provided if you want to serve dynamic requests. --- -##### `buildCommand`Optional +##### `nextBuild`Required ```typescript -public readonly buildCommand: string; +public readonly nextBuild: NextjsBuild; ``` -- *Type:* string -- *Default:* 'npx --yes open-next@^2 build' +- *Type:* NextjsBuild -Optional value used to install NextJS node dependencies. +> [{@link NextjsBuild }]({@link NextjsBuild }) --- -##### `buildPath`Optional +##### `nextjsPath`Required ```typescript -public readonly buildPath: string; +public readonly nextjsPath: string; ``` - *Type:* string -The directory to execute `npm run build` from. - -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. +> [{@link NextjsProps.nextjsPath }]({@link NextjsProps.nextjsPath }) --- -##### `environment`Optional +##### `serverFunction`Required ```typescript -public readonly environment: {[ key: string ]: string}; +public readonly serverFunction: IFunction; ``` -- *Type:* {[ key: string ]: string} +- *Type:* aws-cdk-lib.aws_lambda.IFunction -Custom environment variables to pass to the NextJS build and runtime. +Lambda function to route all non-static requests to. + +Must be provided if you want to serve dynamic requests. --- -##### `projectRoot`Optional +##### `staticAssetsBucket`Required ```typescript -public readonly projectRoot: string; +public readonly staticAssetsBucket: IBucket; ``` -- *Type:* string +- *Type:* aws-cdk-lib.aws_s3.IBucket -Root of your project, if different from `nextjsPath`. +Bucket containing static assets. -Defaults to current working directory. +Must be provided if you want to serve static files. --- -##### `quiet`Optional +##### `basePath`Optional ```typescript -public readonly quiet: boolean; +public readonly basePath: string; ``` -- *Type:* boolean +- *Type:* string -Less build output. +> [{@link NextjsProps.basePath }]({@link NextjsProps.basePath }) --- -##### `sharpLayerArn`Optional +##### `cachePolicies`Optional ```typescript -public readonly sharpLayerArn: string; +public readonly cachePolicies: NextjsCachePolicyProps; ``` -- *Type:* string - -Optional arn for the sharp lambda layer. +- *Type:* NextjsCachePolicyProps -If omitted, the layer will be created. +Override the default CloudFront cache policies created internally. --- -##### `skipFullInvalidation`Optional +##### `cdk`Optional ```typescript -public readonly skipFullInvalidation: boolean; +public readonly cdk: NextjsDistributionCdkProps; ``` -- *Type:* boolean - -By default all CloudFront cache will be invalidated on deployment. +- *Type:* NextjsDistributionCdkProps -This can be set to true to skip the full cache invalidation, which -could be important for some users. +Overrides for created CDK resources. --- -##### `tempBuildDir`Optional +##### `customDomain`Optional ```typescript -public readonly tempBuildDir: string; +public readonly customDomain: string | NextjsDomainProps; ``` -- *Type:* string +- *Type:* string | NextjsDomainProps -Directory to store temporary build files in. +The customDomain for this website. Supports domains that are hosted either on [Route 53](https://aws.amazon.com/route53/) or externally. -Defaults to os.tmpdir(). +Note that you can also migrate externally hosted domains to Route 53 by +[following this guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html). --- -##### `imageOptFunction`Required - -```typescript -public readonly imageOptFunction: IFunction; -``` - -- *Type:* aws-cdk-lib.aws_lambda.IFunction - -Lambda function to optimize images. - -Must be provided if you want to serve dynamic requests. - ---- - -##### `nextBuild`Required - -```typescript -public readonly nextBuild: NextjsBuild; -``` - -- *Type:* NextjsBuild - -Built NextJS app. - ---- - -##### `serverFunction`Required - -```typescript -public readonly serverFunction: IFunction; -``` - -- *Type:* aws-cdk-lib.aws_lambda.IFunction - -Lambda function to route all non-static requests to. - -Must be provided if you want to serve dynamic requests. - ---- - -##### `staticAssetsBucket`Required - -```typescript -public readonly staticAssetsBucket: IBucket; -``` - -- *Type:* aws-cdk-lib.aws_s3.IBucket - -Bucket containing static assets. - -Must be provided if you want to serve static files. - ---- - -##### `basePath`Optional - -```typescript -public readonly basePath: string; -``` - -- *Type:* string - -Optional value to prefix the Next.js site under a /prefix path on CloudFront. Usually used when you deploy multiple Next.js sites on same domain using /sub-path. - -Note, you'll need to set [basePath](https://nextjs.org/docs/app/api-reference/next-config-js/basePath) -in your `next.config.ts` to this value and ensure any files in `public` -folder have correct prefix. - ---- - -*Example* - -```typescript -"/my-base-path" -``` - - -##### `cachePolicies`Optional - -```typescript -public readonly cachePolicies: NextjsCachePolicyProps; -``` - -- *Type:* NextjsCachePolicyProps - -Override the default CloudFront cache policies created internally. - ---- - -##### `cdk`Optional - -```typescript -public readonly cdk: NextjsDistributionCdkProps; -``` - -- *Type:* NextjsDistributionCdkProps - -Overrides for created CDK resources. - ---- - -##### `customDomain`Optional - -```typescript -public readonly customDomain: string | NextjsDomainProps; -``` - -- *Type:* string | NextjsDomainProps - -The customDomain for this website. Supports domains that are hosted either on [Route 53](https://aws.amazon.com/route53/) or externally. - -Note that you can also migrate externally hosted domains to Route 53 by -[following this guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html). - ---- - -*Example* +*Example* ```typescript new NextjsDistribution(this, "Dist", { @@ -3522,7 +3156,7 @@ public readonly distribution: Distribution; - *Type:* aws-cdk-lib.aws_cloudfront.Distribution -Optional CloudFront Distribution created outside of this construct that will be used to add Next.js behaviors and origins onto. Useful with `basePath`. +> [{@link NextjsProps.distribution }]({@link NextjsProps.distribution }) --- @@ -3551,33 +3185,6 @@ Override the default CloudFront origin request policies created internally. --- -##### `stackPrefix`Optional - -```typescript -public readonly stackPrefix: string; -``` - -- *Type:* string - -Optional value to prefix the edge function stack It defaults to "Nextjs". - ---- - -##### `stageName`Optional - -```typescript -public readonly stageName: string; -``` - -- *Type:* string - -Include the name of your deployment stage if present. - -Used to name the edge functions stack. -Required if using SST. - ---- - ### NextjsDomainProps #### Initializer @@ -3699,145 +3306,12 @@ const nextjsImageProps: NextjsImageProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| nextjsPath | string | Relative path to the directory where the NextJS project is located. | -| buildCommand | string | Optional value used to install NextJS node dependencies. | -| buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | | bucket | aws-cdk-lib.aws_s3.IBucket | The S3 bucket holding application images. | -| nextBuild | NextjsBuild | The `NextjsBuild` instance representing the built Nextjs application. | +| nextBuild | NextjsBuild | *No description.* | | lambdaOptions | aws-cdk-lib.aws_lambda.FunctionOptions | Override function properties. | --- -##### `nextjsPath`Required - -```typescript -public readonly nextjsPath: string; -``` - -- *Type:* string - -Relative path to the directory where the NextJS project is located. - -Can be the root of your project (`.`) or a subdirectory (`packages/web`). - ---- - -##### `buildCommand`Optional - -```typescript -public readonly buildCommand: string; -``` - -- *Type:* string -- *Default:* 'npx --yes open-next@^2 build' - -Optional value used to install NextJS node dependencies. - ---- - -##### `buildPath`Optional - -```typescript -public readonly buildPath: string; -``` - -- *Type:* string - -The directory to execute `npm run build` from. - -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. - ---- - -##### `environment`Optional - -```typescript -public readonly environment: {[ key: string ]: string}; -``` - -- *Type:* {[ key: string ]: string} - -Custom environment variables to pass to the NextJS build and runtime. - ---- - -##### `projectRoot`Optional - -```typescript -public readonly projectRoot: string; -``` - -- *Type:* string - -Root of your project, if different from `nextjsPath`. - -Defaults to current working directory. - ---- - -##### `quiet`Optional - -```typescript -public readonly quiet: boolean; -``` - -- *Type:* boolean - -Less build output. - ---- - -##### `sharpLayerArn`Optional - -```typescript -public readonly sharpLayerArn: string; -``` - -- *Type:* string - -Optional arn for the sharp lambda layer. - -If omitted, the layer will be created. - ---- - -##### `skipFullInvalidation`Optional - -```typescript -public readonly skipFullInvalidation: boolean; -``` - -- *Type:* boolean - -By default all CloudFront cache will be invalidated on deployment. - -This can be set to true to skip the full cache invalidation, which -could be important for some users. - ---- - -##### `tempBuildDir`Optional - -```typescript -public readonly tempBuildDir: string; -``` - -- *Type:* string - -Directory to store temporary build files in. - -Defaults to os.tmpdir(). - ---- - ##### `bucket`Required ```typescript @@ -3858,7 +3332,7 @@ public readonly nextBuild: NextjsBuild; - *Type:* NextjsBuild -The `NextjsBuild` instance representing the built Nextjs application. +> [{@link NextjsBuild }]({@link NextjsBuild }) --- @@ -3973,19 +3447,16 @@ const nextjsProps: NextjsProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | | nextjsPath | string | Relative path to the directory where the NextJS project is located. | +| basePath | string | Optional value to prefix the Next.js site under a /prefix path on CloudFront. Usually used when you deploy multiple Next.js sites on same domain using /sub-path. | | buildCommand | string | Optional value used to install NextJS node dependencies. | | buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | -| basePath | string | Optional value to prefix the Next.js site under a /prefix path on CloudFront. Usually used when you deploy multiple Next.js sites on same domain using /sub-path. | | defaults | NextjsDefaultsProps | Allows you to override defaults for the resources created by this construct. | | distribution | aws-cdk-lib.aws_cloudfront.Distribution | Optional CloudFront Distribution created outside of this construct that will be used to add Next.js behaviors and origins onto. Useful with `basePath`. | +| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build **and** runtime. | | imageOptimizationBucket | aws-cdk-lib.aws_s3.IBucket | Optional S3 Bucket to use, defaults to assets bucket. | +| quiet | boolean | Less build output. | | skipBuild | boolean | Skips running Next.js build. Useful if you want to deploy `Nextjs` but haven't made any changes to Next.js app code. | +| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | --- @@ -4003,139 +3474,58 @@ Can be the root of your project (`.`) or a subdirectory (`packages/web`). --- -##### `buildCommand`Optional +##### `basePath`Optional ```typescript -public readonly buildCommand: string; +public readonly basePath: string; ``` - *Type:* string -- *Default:* 'npx --yes open-next@^2 build' -Optional value used to install NextJS node dependencies. +Optional value to prefix the Next.js site under a /prefix path on CloudFront. Usually used when you deploy multiple Next.js sites on same domain using /sub-path. ---- - -##### `buildPath`Optional - -```typescript -public readonly buildPath: string; -``` - -- *Type:* string - -The directory to execute `npm run build` from. - -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. - ---- - -##### `environment`Optional - -```typescript -public readonly environment: {[ key: string ]: string}; -``` - -- *Type:* {[ key: string ]: string} - -Custom environment variables to pass to the NextJS build and runtime. - ---- - -##### `projectRoot`Optional - -```typescript -public readonly projectRoot: string; -``` - -- *Type:* string - -Root of your project, if different from `nextjsPath`. - -Defaults to current working directory. - ---- - -##### `quiet`Optional - -```typescript -public readonly quiet: boolean; -``` - -- *Type:* boolean - -Less build output. - ---- - -##### `sharpLayerArn`Optional - -```typescript -public readonly sharpLayerArn: string; -``` - -- *Type:* string - -Optional arn for the sharp lambda layer. - -If omitted, the layer will be created. +Note, you'll need to set [basePath](https://nextjs.org/docs/app/api-reference/next-config-js/basePath) +in your `next.config.ts` to this value and ensure any files in `public` +folder have correct prefix. --- -##### `skipFullInvalidation`Optional +*Example* ```typescript -public readonly skipFullInvalidation: boolean; +"/my-base-path" ``` -- *Type:* boolean - -By default all CloudFront cache will be invalidated on deployment. - -This can be set to true to skip the full cache invalidation, which -could be important for some users. - ---- -##### `tempBuildDir`Optional +##### `buildCommand`Optional ```typescript -public readonly tempBuildDir: string; +public readonly buildCommand: string; ``` - *Type:* string +- *Default:* 'npx --yes open-next@^2 build' -Directory to store temporary build files in. - -Defaults to os.tmpdir(). +Optional value used to install NextJS node dependencies. --- -##### `basePath`Optional +##### `buildPath`Optional ```typescript -public readonly basePath: string; +public readonly buildPath: string; ``` - *Type:* string -Optional value to prefix the Next.js site under a /prefix path on CloudFront. Usually used when you deploy multiple Next.js sites on same domain using /sub-path. +The directory to execute `npm run build` from. -Note, you'll need to set [basePath](https://nextjs.org/docs/app/api-reference/next-config-js/basePath) -in your `next.config.ts` to this value and ensure any files in `public` -folder have correct prefix. +By default, it is `nextjsPath`. +Can be overridden, particularly useful for monorepos where `build` is expected to run +at the root of the project. --- -*Example* - -```typescript -"/my-base-path" -``` - - ##### `defaults`Optional ```typescript @@ -4160,104 +3550,7 @@ Optional CloudFront Distribution created outside of this construct that will be --- -##### `imageOptimizationBucket`Optional - -```typescript -public readonly imageOptimizationBucket: IBucket; -``` - -- *Type:* aws-cdk-lib.aws_s3.IBucket - -Optional S3 Bucket to use, defaults to assets bucket. - ---- - -##### `skipBuild`Optional - -```typescript -public readonly skipBuild: boolean; -``` - -- *Type:* boolean -- *Default:* false - -Skips running Next.js build. Useful if you want to deploy `Nextjs` but haven't made any changes to Next.js app code. - ---- - -### NextjsRevalidationProps - -#### Initializer - -```typescript -import { NextjsRevalidationProps } from 'cdk-nextjs-standalone' - -const nextjsRevalidationProps: NextjsRevalidationProps = { ... } -``` - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| nextjsPath | string | Relative path to the directory where the NextJS project is located. | -| buildCommand | string | Optional value used to install NextJS node dependencies. | -| buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | -| nextBuild | NextjsBuild | The `NextjsBuild` instance representing the built Nextjs application. | -| serverFunction | NextjsServer | The main NextJS server handler lambda function. | -| lambdaOptions | aws-cdk-lib.aws_lambda.FunctionOptions | Override function properties. | - ---- - -##### `nextjsPath`Required - -```typescript -public readonly nextjsPath: string; -``` - -- *Type:* string - -Relative path to the directory where the NextJS project is located. - -Can be the root of your project (`.`) or a subdirectory (`packages/web`). - ---- - -##### `buildCommand`Optional - -```typescript -public readonly buildCommand: string; -``` - -- *Type:* string -- *Default:* 'npx --yes open-next@^2 build' - -Optional value used to install NextJS node dependencies. - ---- - -##### `buildPath`Optional - -```typescript -public readonly buildPath: string; -``` - -- *Type:* string - -The directory to execute `npm run build` from. - -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. - ---- - -##### `environment`Optional +##### `environment`Optional ```typescript public readonly environment: {[ key: string ]: string}; @@ -4265,25 +3558,23 @@ public readonly environment: {[ key: string ]: string}; - *Type:* {[ key: string ]: string} -Custom environment variables to pass to the NextJS build and runtime. +Custom environment variables to pass to the NextJS build **and** runtime. --- -##### `projectRoot`Optional +##### `imageOptimizationBucket`Optional ```typescript -public readonly projectRoot: string; +public readonly imageOptimizationBucket: IBucket; ``` -- *Type:* string - -Root of your project, if different from `nextjsPath`. +- *Type:* aws-cdk-lib.aws_s3.IBucket -Defaults to current working directory. +Optional S3 Bucket to use, defaults to assets bucket. --- -##### `quiet`Optional +##### `quiet`Optional ```typescript public readonly quiet: boolean; @@ -4295,21 +3586,20 @@ Less build output. --- -##### `sharpLayerArn`Optional +##### `skipBuild`Optional ```typescript -public readonly sharpLayerArn: string; +public readonly skipBuild: boolean; ``` -- *Type:* string - -Optional arn for the sharp lambda layer. +- *Type:* boolean +- *Default:* false -If omitted, the layer will be created. +Skips running Next.js build. Useful if you want to deploy `Nextjs` but haven't made any changes to Next.js app code. --- -##### `skipFullInvalidation`Optional +##### `skipFullInvalidation`Optional ```typescript public readonly skipFullInvalidation: boolean; @@ -4324,17 +3614,23 @@ could be important for some users. --- -##### `tempBuildDir`Optional +### NextjsRevalidationProps + +#### Initializer ```typescript -public readonly tempBuildDir: string; -``` +import { NextjsRevalidationProps } from 'cdk-nextjs-standalone' -- *Type:* string +const nextjsRevalidationProps: NextjsRevalidationProps = { ... } +``` -Directory to store temporary build files in. +#### Properties -Defaults to os.tmpdir(). +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| nextBuild | NextjsBuild | *No description.* | +| serverFunction | NextjsServer | *No description.* | +| lambdaOptions | aws-cdk-lib.aws_lambda.FunctionOptions | Override function properties. | --- @@ -4346,7 +3642,7 @@ public readonly nextBuild: NextjsBuild; - *Type:* NextjsBuild -The `NextjsBuild` instance representing the built Nextjs application. +> [{@link NextjsBuild }]({@link NextjsBuild }) --- @@ -4358,7 +3654,7 @@ public readonly serverFunction: NextjsServer; - *Type:* NextjsServer -The main NextJS server handler lambda function. +> [{@link NextjsServer }]({@link NextjsServer }) --- @@ -4388,61 +3684,37 @@ const nextjsServerProps: NextjsServerProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| nextjsPath | string | Relative path to the directory where the NextJS project is located. | -| buildCommand | string | Optional value used to install NextJS node dependencies. | -| buildPath | string | The directory to execute `npm run build` from. | -| environment | {[ key: string ]: string} | Custom environment variables to pass to the NextJS build and runtime. | -| projectRoot | string | Root of your project, if different from `nextjsPath`. | -| quiet | boolean | Less build output. | -| sharpLayerArn | string | Optional arn for the sharp lambda layer. | -| skipFullInvalidation | boolean | By default all CloudFront cache will be invalidated on deployment. | -| tempBuildDir | string | Directory to store temporary build files in. | -| nextBuild | NextjsBuild | Built nextJS application. | +| nextBuild | NextjsBuild | *No description.* | | staticAssetBucket | aws-cdk-lib.aws_s3.IBucket | Static asset bucket. | +| environment | {[ key: string ]: string} | *No description.* | | lambda | aws-cdk-lib.aws_lambda.FunctionOptions | Override function properties. | +| quiet | boolean | *No description.* | --- -##### `nextjsPath`Required - -```typescript -public readonly nextjsPath: string; -``` - -- *Type:* string - -Relative path to the directory where the NextJS project is located. - -Can be the root of your project (`.`) or a subdirectory (`packages/web`). - ---- - -##### `buildCommand`Optional +##### `nextBuild`Required ```typescript -public readonly buildCommand: string; +public readonly nextBuild: NextjsBuild; ``` -- *Type:* string -- *Default:* 'npx --yes open-next@^2 build' +- *Type:* NextjsBuild -Optional value used to install NextJS node dependencies. +> [{@link NextjsBuild }]({@link NextjsBuild }) --- -##### `buildPath`Optional +##### `staticAssetBucket`Required ```typescript -public readonly buildPath: string; +public readonly staticAssetBucket: IBucket; ``` -- *Type:* string +- *Type:* aws-cdk-lib.aws_s3.IBucket -The directory to execute `npm run build` from. +Static asset bucket. -By default, it is `nextjsPath`. -Can be overridden, particularly useful for monorepos where `build` is expected to run -at the root of the project. +Function needs bucket to read from cache. --- @@ -4454,21 +3726,19 @@ public readonly environment: {[ key: string ]: string}; - *Type:* {[ key: string ]: string} -Custom environment variables to pass to the NextJS build and runtime. +> [{@link NextjsProps.environment }]({@link NextjsProps.environment }) --- -##### `projectRoot`Optional +##### `lambda`Optional ```typescript -public readonly projectRoot: string; +public readonly lambda: FunctionOptions; ``` -- *Type:* string - -Root of your project, if different from `nextjsPath`. +- *Type:* aws-cdk-lib.aws_lambda.FunctionOptions -Defaults to current working directory. +Override function properties. --- @@ -4480,88 +3750,7 @@ public readonly quiet: boolean; - *Type:* boolean -Less build output. - ---- - -##### `sharpLayerArn`Optional - -```typescript -public readonly sharpLayerArn: string; -``` - -- *Type:* string - -Optional arn for the sharp lambda layer. - -If omitted, the layer will be created. - ---- - -##### `skipFullInvalidation`Optional - -```typescript -public readonly skipFullInvalidation: boolean; -``` - -- *Type:* boolean - -By default all CloudFront cache will be invalidated on deployment. - -This can be set to true to skip the full cache invalidation, which -could be important for some users. - ---- - -##### `tempBuildDir`Optional - -```typescript -public readonly tempBuildDir: string; -``` - -- *Type:* string - -Directory to store temporary build files in. - -Defaults to os.tmpdir(). - ---- - -##### `nextBuild`Required - -```typescript -public readonly nextBuild: NextjsBuild; -``` - -- *Type:* NextjsBuild - -Built nextJS application. - ---- - -##### `staticAssetBucket`Required - -```typescript -public readonly staticAssetBucket: IBucket; -``` - -- *Type:* aws-cdk-lib.aws_s3.IBucket - -Static asset bucket. - -Function needs bucket to read from cache. - ---- - -##### `lambda`Optional - -```typescript -public readonly lambda: FunctionOptions; -``` - -- *Type:* aws-cdk-lib.aws_lambda.FunctionOptions - -Override function properties. +> [{@link NextjsProps.quiet }]({@link NextjsProps.quiet }) --- diff --git a/docs/major-changes.md b/docs/major-changes.md index 97726622..c7336db8 100644 --- a/docs/major-changes.md +++ b/docs/major-changes.md @@ -16,6 +16,11 @@ - Remove `BaseSiteEnvironmentOutputsInfo, BaseSiteReplaceProps` exports as not used anymore - Remove `compressionLevel` to simplify configuration. We use optimal for windows or max compression for unix - Remove `nodeEnv` because it can be configured through `environment` prop. +- Remove `sharpLayerArn` because it's not used +- Remove `projectRoot` because it's not used +- Remove `NextjsBaseProps` to simplify props +- Remove `projectRoot` as it's not being used +- Remove `tempBuildDir` as it's not being used ## v3 diff --git a/src/Nextjs.ts b/src/Nextjs.ts index 5cce9cb4..4711503e 100644 --- a/src/Nextjs.ts +++ b/src/Nextjs.ts @@ -1,12 +1,9 @@ -import * as fs from 'node:fs'; -import * as os from 'os'; -import * as path from 'path'; import { Distribution } from 'aws-cdk-lib/aws-cloudfront'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { FunctionOptions } from 'aws-cdk-lib/aws-lambda'; import * as s3 from 'aws-cdk-lib/aws-s3'; import { Construct } from 'constructs'; -import { BaseSiteDomainProps, NextjsBaseProps } from './NextjsBase'; +import { BaseSiteDomainProps } from './NextjsBase'; import { NextjsBuild } from './NextjsBuild'; import { NextjsDistribution, NextjsDistributionProps } from './NextjsDistribution'; import { NextjsImage } from './NextjsImage'; @@ -40,22 +37,7 @@ export interface NextjsDefaultsProps { readonly distribution?: NextjsDistributionProps | any; } -export interface NextjsProps extends NextjsBaseProps { - /** - * Optional S3 Bucket to use, defaults to assets bucket - */ - readonly imageOptimizationBucket?: s3.IBucket; - /** - * Allows you to override defaults for the resources created by this - * construct. - */ - readonly defaults?: NextjsDefaultsProps; - /** - * Skips running Next.js build. Useful if you want to deploy `Nextjs` but - * haven't made any changes to Next.js app code. - * @default false - */ - readonly skipBuild?: boolean; +export interface NextjsProps { /** * Optional value to prefix the Next.js site under a /prefix path on CloudFront. * Usually used when you deploy multiple Next.js sites on same domain using /sub-path @@ -66,11 +48,56 @@ export interface NextjsProps extends NextjsBaseProps { * @example "/my-base-path" */ readonly basePath?: string; + /** + * Optional value used to install NextJS node dependencies. + * @default 'npx --yes open-next@^2 build' + */ + readonly buildCommand?: string; + /** + * The directory to execute `npm run build` from. By default, it is `nextjsPath`. + * Can be overridden, particularly useful for monorepos where `build` is expected to run + * at the root of the project. + */ + readonly buildPath?: string; + /** + * Allows you to override defaults for the resources created by this + * construct. + */ + readonly defaults?: NextjsDefaultsProps; /** * Optional CloudFront Distribution created outside of this construct that will * be used to add Next.js behaviors and origins onto. Useful with `basePath`. */ readonly distribution?: Distribution; + /** + * Custom environment variables to pass to the NextJS build **and** runtime. + */ + readonly environment?: Record; + /** + * Optional S3 Bucket to use, defaults to assets bucket + */ + readonly imageOptimizationBucket?: s3.IBucket; + /** + * Relative path to the directory where the NextJS project is located. + * Can be the root of your project (`.`) or a subdirectory (`packages/web`). + */ + readonly nextjsPath: string; + /** + * Less build output. + */ + readonly quiet?: boolean; + /** + * Skips running Next.js build. Useful if you want to deploy `Nextjs` but + * haven't made any changes to Next.js app code. + * @default false + */ + readonly skipBuild?: boolean; + /** + * By default all CloudFront cache will be invalidated on deployment. + * This can be set to true to skip the full cache invalidation, which + * could be important for some users. + */ + readonly skipFullInvalidation?: boolean; } /** @@ -113,17 +140,6 @@ export class Nextjs extends Construct { */ public distribution: NextjsDistribution; - /** - * Where build-time assets for deployment are stored. - */ - public get tempBuildDir(): string { - return this.props.tempBuildDir - ? path.resolve( - path.join(this.props.tempBuildDir, `nextjs-cdk-build-${this.node.id}-${this.node.addr.substring(0, 4)}`) - ) - : fs.mkdtempSync(path.join(os.tmpdir(), 'nextjs-cdk-build-')); - } - /** * Revalidation handler and queue. */ @@ -136,7 +152,7 @@ export class Nextjs extends Construct { super(scope, id); // build nextjs app - this.nextBuild = new NextjsBuild(this, id, { ...props, tempBuildDir: this.tempBuildDir }); + this.nextBuild = new NextjsBuild(this, id, props); // deploy nextjs static assets to s3 this.staticAssets = new NextjsStaticAssets(this, 'StaticAssets', { @@ -148,7 +164,6 @@ export class Nextjs extends Construct { this.serverFunction = new NextjsServer(this, 'Server', { ...props, - tempBuildDir: this.tempBuildDir, nextBuild: this.nextBuild, lambda: props.defaults?.lambda, staticAssetBucket: this.staticAssets.bucket, @@ -172,7 +187,6 @@ export class Nextjs extends Construct { ...props, ...props.defaults?.distribution, staticAssetsBucket: this.staticAssets.bucket, - tempBuildDir: this.tempBuildDir, nextBuild: this.nextBuild, serverFunction: this.serverFunction.lambdaFunction, imageOptFunction: this.imageOptimizationFunction, diff --git a/src/NextjsBase.ts b/src/NextjsBase.ts index e8369d00..4661c8d0 100644 --- a/src/NextjsBase.ts +++ b/src/NextjsBase.ts @@ -1,65 +1,6 @@ import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'; import { IHostedZone } from 'aws-cdk-lib/aws-route53'; -/** - * Common props shared across NextJS-related CDK constructs. - */ -export interface NextjsBaseProps { - /** - * Relative path to the directory where the NextJS project is located. - * Can be the root of your project (`.`) or a subdirectory (`packages/web`). - */ - readonly nextjsPath: string; - - /** - * The directory to execute `npm run build` from. By default, it is `nextjsPath`. - * Can be overridden, particularly useful for monorepos where `build` is expected to run - * at the root of the project. - */ - readonly buildPath?: string; - - /** - * Root of your project, if different from `nextjsPath`. - * Defaults to current working directory. - */ - readonly projectRoot?: string; - - /** - * Custom environment variables to pass to the NextJS build and runtime. - */ - readonly environment?: Record; - - /** - * Directory to store temporary build files in. - * Defaults to os.tmpdir(). - */ - readonly tempBuildDir?: string; // move to NextjsBuildProps? - - /** - * Optional value used to install NextJS node dependencies. - * @default 'npx --yes open-next@^2 build' - */ - readonly buildCommand?: string; - - /** - * Less build output. - */ - readonly quiet?: boolean; - - /** - * Optional arn for the sharp lambda layer. - * If omitted, the layer will be created. - */ - readonly sharpLayerArn?: string; - - /** - * By default all CloudFront cache will be invalidated on deployment. - * This can be set to true to skip the full cache invalidation, which - * could be important for some users. - */ - readonly skipFullInvalidation?: boolean; -} - ///// stuff below taken from https://github.com/serverless-stack/sst/blob/8d377e941467ced81d8cc31ee67d5a06550f04d4/packages/resources/src/BaseSite.ts export interface BaseSiteDomainProps { diff --git a/src/NextjsBuild.ts b/src/NextjsBuild.ts index a982d822..85c5491e 100644 --- a/src/NextjsBuild.ts +++ b/src/NextjsBuild.ts @@ -12,15 +12,35 @@ import { NEXTJS_CACHE_DIR, NEXTJS_BUILD_DYNAMODB_PROVIDER_FN_DIR, } from './constants'; -import { NextjsBaseProps } from './NextjsBase'; +import type { NextjsProps } from './Nextjs'; import { NextjsBucketDeployment } from './NextjsBucketDeployment'; import { listDirectory } from './utils/list-directories'; -export interface NextjsBuildProps extends NextjsBaseProps { +export interface NextjsBuildProps { /** - * @see `NextjsProps.skipBuild` + * @see {@link NextjsProps.buildCommand} */ - readonly skipBuild?: boolean; + readonly buildCommand?: NextjsProps['buildCommand']; + /** + * @see {@link NextjsProps.buildPath} + */ + readonly buildPath?: NextjsProps['buildPath']; + /** + * @see {@link NextjsProps.environment} + */ + readonly environment?: NextjsProps['environment']; + /** + * @see {@link NextjsProps.nextjsPath} + */ + readonly nextjsPath: NextjsProps['nextjsPath']; + /** + * @see {@link NextjsProps.quiet} + */ + readonly quiet?: NextjsProps['quiet']; + /** + * @see {@link NextjsProps.skipBuild} + */ + readonly skipBuild?: NextjsProps['skipBuild']; } /** @@ -113,7 +133,7 @@ export class NextjsBuild extends Construct { const buildCommand = this.props.buildCommand ?? 'npx open-next@^2 build'; // run build if (!this.props.quiet) { - console.debug(`├ Running "${buildCommand}" in`, buildPath); + console.debug(`Running "${buildCommand}" in`, buildPath); } // will throw if build fails - which is desired execSync(buildCommand, { diff --git a/src/NextjsDistribution.ts b/src/NextjsDistribution.ts index f6dcd24d..d0418f0f 100644 --- a/src/NextjsDistribution.ts +++ b/src/NextjsDistribution.ts @@ -14,7 +14,8 @@ import * as route53Targets from 'aws-cdk-lib/aws-route53-targets'; import * as s3 from 'aws-cdk-lib/aws-s3'; import { Construct } from 'constructs'; import { DEFAULT_STATIC_MAX_AGE, NEXTJS_BUILD_DIR, NEXTJS_STATIC_DIR } from './constants'; -import { BaseSiteDomainProps, NextjsBaseProps } from './NextjsBase'; +import { NextjsProps } from './Nextjs'; +import { BaseSiteDomainProps } from './NextjsBase'; import { NextjsBuild } from './NextjsBuild'; export interface NextjsDomainProps extends BaseSiteDomainProps {} @@ -47,45 +48,19 @@ export interface NextjsOriginRequestPolicyProps { readonly imageOptimizationOriginRequestPolicy?: cloudfront.IOriginRequestPolicy; } -export interface NextjsDistributionProps extends NextjsBaseProps { +export interface NextjsDistributionProps { /** - * Bucket containing static assets. - * Must be provided if you want to serve static files. - */ - readonly staticAssetsBucket: s3.IBucket; - - /** - * Lambda function to route all non-static requests to. - * Must be provided if you want to serve dynamic requests. - */ - readonly serverFunction: lambda.IFunction; - - /** - * Lambda function to optimize images. - * Must be provided if you want to serve dynamic requests. - */ - readonly imageOptFunction: lambda.IFunction; - - /** - * Overrides for created CDK resources. + * @see {@link NextjsProps.basePath} */ - readonly cdk?: NextjsDistributionCdkProps; - - /** - * Built NextJS app. - */ - readonly nextBuild: NextjsBuild; - + readonly basePath?: NextjsProps['basePath']; /** * Override the default CloudFront cache policies created internally. */ readonly cachePolicies?: NextjsCachePolicyProps; - /** - * Override the default CloudFront origin request policies created internally. + * Overrides for created CDK resources. */ - readonly originRequestPolicies?: NextjsOriginRequestPolicyProps; - + readonly cdk?: NextjsDistributionCdkProps; /** * The customDomain for this website. Supports domains that are hosted * either on [Route 53](https://aws.amazon.com/route53/) or externally. @@ -107,42 +82,42 @@ export interface NextjsDistributionProps extends NextjsBaseProps { * }); */ readonly customDomain?: string | NextjsDomainProps; - - /** - * Include the name of your deployment stage if present. - * Used to name the edge functions stack. - * Required if using SST. - */ - readonly stageName?: string; - /** - * Optional value to prefix the edge function stack - * It defaults to "Nextjs" + * @see {@link NextjsProps.distribution} */ - readonly stackPrefix?: string; - + readonly distribution?: NextjsProps['distribution']; /** * Override lambda function url auth type * @default "NONE" */ readonly functionUrlAuthType?: lambda.FunctionUrlAuthType; - /** - * Optional value to prefix the Next.js site under a /prefix path on CloudFront. - * Usually used when you deploy multiple Next.js sites on same domain using /sub-path - * - * Note, you'll need to set [basePath](https://nextjs.org/docs/app/api-reference/next-config-js/basePath) - * in your `next.config.ts` to this value and ensure any files in `public` - * folder have correct prefix. - * @example "/my-base-path" + * Lambda function to optimize images. + * Must be provided if you want to serve dynamic requests. */ - readonly basePath?: string; - + readonly imageOptFunction: lambda.IFunction; + /** + * @see {@link NextjsBuild} + */ + readonly nextBuild: NextjsBuild; /** - * Optional CloudFront Distribution created outside of this construct that will - * be used to add Next.js behaviors and origins onto. Useful with `basePath`. + * @see {@link NextjsProps.nextjsPath} */ - readonly distribution?: Distribution; + readonly nextjsPath: NextjsProps['nextjsPath']; + /** + * Override the default CloudFront origin request policies created internally. + */ + readonly originRequestPolicies?: NextjsOriginRequestPolicyProps; + /** + * Lambda function to route all non-static requests to. + * Must be provided if you want to serve dynamic requests. + */ + readonly serverFunction: lambda.IFunction; + /** + * Bucket containing static assets. + * Must be provided if you want to serve static files. + */ + readonly staticAssetsBucket: s3.IBucket; } /** diff --git a/src/NextjsImage.ts b/src/NextjsImage.ts index e2339aef..0f4c1f05 100644 --- a/src/NextjsImage.ts +++ b/src/NextjsImage.ts @@ -1,11 +1,10 @@ import { Code, Function as LambdaFunction, FunctionOptions } from 'aws-cdk-lib/aws-lambda'; import { IBucket } from 'aws-cdk-lib/aws-s3'; import { Construct } from 'constructs'; -import { NextjsBaseProps } from './NextjsBase'; import type { NextjsBuild } from './NextjsBuild'; import { getCommonFunctionProps } from './utils/common-lambda-props'; -export interface NextjsImageProps extends NextjsBaseProps { +export interface NextjsImageProps { /** * The S3 bucket holding application images. */ @@ -15,7 +14,7 @@ export interface NextjsImageProps extends NextjsBaseProps { */ readonly lambdaOptions?: FunctionOptions; /** - * The `NextjsBuild` instance representing the built Nextjs application. + * @see {@link NextjsBuild} */ readonly nextBuild: NextjsBuild; } diff --git a/src/NextjsRevalidation.ts b/src/NextjsRevalidation.ts index 82db7252..d9b6cfa4 100644 --- a/src/NextjsRevalidation.ts +++ b/src/NextjsRevalidation.ts @@ -8,24 +8,21 @@ import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { Queue } from 'aws-cdk-lib/aws-sqs'; import { Provider } from 'aws-cdk-lib/custom-resources'; import { Construct } from 'constructs'; -import { NextjsBaseProps } from './NextjsBase'; import { NextjsBuild } from './NextjsBuild'; import { NextjsServer } from './NextjsServer'; import { getCommonFunctionProps } from './utils/common-lambda-props'; -export interface NextjsRevalidationProps extends NextjsBaseProps { +export interface NextjsRevalidationProps { /** * Override function properties. */ readonly lambdaOptions?: FunctionOptions; - /** - * The `NextjsBuild` instance representing the built Nextjs application. + * @see {@link NextjsBuild} */ readonly nextBuild: NextjsBuild; - /** - * The main NextJS server handler lambda function. + * @see {@link NextjsServer} */ readonly serverFunction: NextjsServer; } diff --git a/src/NextjsServer.ts b/src/NextjsServer.ts index 81efc3ae..f2947fc6 100644 --- a/src/NextjsServer.ts +++ b/src/NextjsServer.ts @@ -8,7 +8,7 @@ import { Bucket, IBucket } from 'aws-cdk-lib/aws-s3'; import { Asset } from 'aws-cdk-lib/aws-s3-assets'; import { Construct } from 'constructs'; import { CACHE_BUCKET_KEY_PREFIX } from './constants'; -import { NextjsBaseProps } from './NextjsBase'; +import { NextjsProps } from './Nextjs'; import { NextjsBucketDeployment } from './NextjsBucketDeployment'; import { NextjsBuild } from './NextjsBuild'; import { getCommonFunctionProps } from './utils/common-lambda-props'; @@ -16,17 +16,23 @@ import { createArchive } from './utils/create-archive'; export type EnvironmentVars = Record; -export interface NextjsServerProps extends NextjsBaseProps { +export interface NextjsServerProps { /** - * Built nextJS application. + * @see {@link NextjsProps.environment} */ - readonly nextBuild: NextjsBuild; - + readonly environment?: NextjsProps['environment']; /** * Override function properties. */ readonly lambda?: FunctionOptions; - + /** + * @see {@link NextjsBuild} + */ + readonly nextBuild: NextjsBuild; + /** + * @see {@link NextjsProps.quiet} + */ + readonly quiet?: NextjsProps['quiet']; /** * Static asset bucket. Function needs bucket to read from cache. */ diff --git a/src/index.ts b/src/index.ts index 477746c1..b5914291 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { BaseSiteDomainProps, NextjsBaseProps } from './NextjsBase'; +export { BaseSiteDomainProps } from './NextjsBase'; // L2 constructs export { NextjsStaticAssets, NextjsStaticAssetsProps } from './NextjsStaticAssets';