jetbridge / cdk-nextjs

Deploy a NextJS application using AWS CDK
https://constructs.dev/packages/cdk-nextjs-standalone
Apache License 2.0
261 stars 43 forks source link

feat: add NextjsOverrides #181

Closed bestickley closed 7 months ago

bestickley commented 7 months ago

Fixes #168, #104. This PR implements NextjsOverrides discussed in https://github.com/jetbridge/cdk-nextjs/discussions/132. This feature enables deep levels of customization over this construct. An incomplete example below. See source code for all options.

new Nextjs(this, 'Nextjs', {
  nextjsPath: './web', // relative path from your project root to NextJS
  overrides: {
    nextjsBucketDeployment: { functionProps: { ... }, ... },
    nextjsDistribution: {
      cloudFrontFunctionProps: { ... },
      distributionProps: { ... },
      edgeFunctionProps: { ... },
      imageBehaviorOptions: { ... },
      imageCachePolicyProps: { ... },
      imageHttpOriginProps: { ... },
      ...
    },
    nextjsDomain: { ... },
    nextjsImage: { ... },
    nextjsInvalidation: { ... },
    nextjsRevalidation: { ... },
    nextjsServer: { ... },
    nextjsStaticAssets: { ... },
  }
});

In the spirit of DRY, I've removed NextjsDefaults favoring NextjsOverrides for reasons stated above. Additionally, NextjsOverrides gives better type support because we're creating optional interfaces based off AWS CDK interfaces that have required properties with @mrgrain/jsii-struct-builder. This prevents having to use any.

bestickley commented 7 months ago

@kevin-mitchell, @onhate, would appreciate your review.

kevin-mitchell commented 7 months ago

This looks great, and I love the improvement re: types (and the remove of so many | any!).

Only thing I can really think to add (but am not sure how this would be done) is if there could be something added to the readme / contributions guide about the pattern you established for the optional parameters? Honestly ti's probably not needed, I wasn't familiar with the syntax / tooling you added but quickly looked through .projenrc.ts and was able to figure it out.

onhate commented 7 months ago

I like it better than it is now :)

bestickley commented 7 months ago

@kevin-mitchell, I have added docs on jsii struct builder. great suggestion. @onhate, awesome. thank you for reviewing!

bestickley commented 7 months ago

@revmischa, approved on Discord. Merging 🚀