Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add staticResponseHeadersPolicy to NextjsProps #118

Closed
Lightbirdv opened this issue Jun 23, 2023 · 4 comments · Fixed by #153
Closed

Add staticResponseHeadersPolicy to NextjsProps #118

Lightbirdv opened this issue Jun 23, 2023 · 4 comments · Fixed by #153
Milestone

Comments

@Lightbirdv
Copy link

I would like to reuse the same policy for different cloudfront distributions. It is possible for the cachePolicies and the originRequestPolicies. So could staticResponseHeadersPolicy be added to the NextjsProps to be reused?

@bestickley
Copy link
Collaborator

bestickley commented Jul 6, 2023

Hi @Lightbirdv, yes, you can customize the CloudFront Distrubtion's cache policies and origin request policies like this:

import { Nextjs, type NextjsDistributionProps } from "cdk-nextjs-standalone";
import {
  type DistributionProps,
  CachePolicy,
  OriginRequestPolicy,
} from "aws-cdk-lib/aws-cloudfront";

new Nextjs(this, "Nextjs", {
  defaults: {
    distribution: {
      cachePolicies: {
        imageCachePolicy: new CachePolicy(this, "ImageCachePolicy", {}),
        lambdaCachePolicy: new CachePolicy(this, "LambdaCachePolicy", {}),
        staticCachePolicy: new CachePolicy(this, "StaticCachePolicy", {}),
      },
      originRequestPolicies: {
        fallbackOriginRequestPolicy: new OriginRequestPolicy(this, "FallbackOriginRequestPolicy", {}),
        imageOptimizationOriginRequestPolicy: new OriginRequestPolicy(this, "ImageOptOriginRequestPolicy", {}),
        lambdaOriginRequestPolicy: new OriginRequestPolicy(this, "LambdaOriginRequestPolicy", {}),
      },
    } satisfies Partial<NextjsDistributionProps>
  }
});

Does this answer your question?

@bestickley
Copy link
Collaborator

Or are you referring to being able to customize this construct?

@bestickley bestickley added this to the Version 4 Stable milestone Oct 23, 2023
@Lightbirdv
Copy link
Author

Yes I am referring to the construct you linked. Since I want to customize and reuse it. I would be nice if we would be able to add the policy via the props

@bestickley
Copy link
Collaborator

bestickley commented Oct 25, 2023

@Lightbirdv, I approved the PR raised to fix this, but I'm working towards a broader solution for this problem with an overrides top level prop. I've created an RFC for it here: #132. Could you please review it and share your thoughts?

Also, could you please share some sample code for how you're using staticResponseHeaderPolicy and it's use case? I'd like to keep a list of common customizations to this construct and their use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants