From e0318f5621f2ac9a06f03f9954993eb38944dae9 Mon Sep 17 00:00:00 2001 From: Ben Stickley Date: Fri, 20 Oct 2023 08:06:47 -0400 Subject: [PATCH] fix: example and add validateProps method to Nextjs to ensure user doesn't think they can customize distribution when passing in distribution --- examples/multiple-sites/src/stack.ts | 16 ++++------------ src/Nextjs.ts | 10 ++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/multiple-sites/src/stack.ts b/examples/multiple-sites/src/stack.ts index d2d40185..cfc004f9 100644 --- a/examples/multiple-sites/src/stack.ts +++ b/examples/multiple-sites/src/stack.ts @@ -24,24 +24,16 @@ export class MultipleSitesStack extends Stack { }, }) - const app1 = new Nextjs(this, 'app-router', { + new Nextjs(this, 'app-router', { nextjsPath: '../../open-next/examples/app-router', basePath: '/app-router', - defaults: { - distribution: { - cdk: { distribution } - } - } + distribution, }); - const app2 = new Nextjs(this, 'pages-router', { + new Nextjs(this, 'pages-router', { nextjsPath: '../../open-next/examples/pages-router', basePath: '/pages-router', - defaults: { - distribution: { - cdk: { distribution } - } - } + distribution, }); new CfnOutput(this, "CloudFrontDistributionDomain", { diff --git a/src/Nextjs.ts b/src/Nextjs.ts index bda58bed..272c5fcc 100644 --- a/src/Nextjs.ts +++ b/src/Nextjs.ts @@ -131,6 +131,8 @@ export class Nextjs extends Construct { constructor(scope: Construct, id: string, protected props: NextjsProps) { super(scope, id); + this.validateProps(props); + // build nextjs app this.nextBuild = new NextjsBuild(this, id, { ...props, tempBuildDir: this.tempBuildDir }); @@ -196,4 +198,12 @@ export class Nextjs extends Construct { public get bucket(): s3.IBucket { return this.staticAssets.bucket; } + + private validateProps(props: NextjsProps) { + if (props.distribution && props.defaults?.distribution) { + throw new Error( + 'distribution and defaults.distribution were passed as props to Nextjs. defaults.distribution will have no affect. Please removed.' + ); + } + } }