@jaypie/constructs 1.2.17 → 1.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/JaypieNextJs.d.ts +9 -1
- package/dist/cjs/index.cjs +30 -15
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/JaypieNextJs.d.ts +9 -1
- package/dist/esm/index.js +30 -15
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,8 +16,16 @@ export interface JaypieNextjsProps {
|
|
|
16
16
|
* - String: used directly as the domain name
|
|
17
17
|
* - Object: passed to envHostname() to construct the domain name
|
|
18
18
|
* - { component, domain, env, subdomain }
|
|
19
|
+
*
|
|
20
|
+
* To deploy without a domain (CloudFront URL only), set domainProps: false
|
|
19
21
|
*/
|
|
20
22
|
domainName?: string | DomainNameConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Set to false to deploy without a custom domain.
|
|
25
|
+
* When false, the application will only be accessible via CloudFront URL.
|
|
26
|
+
* This overrides any domainName configuration.
|
|
27
|
+
*/
|
|
28
|
+
domainProps?: false;
|
|
21
29
|
/**
|
|
22
30
|
* DynamoDB tables to grant read/write access to the Next.js server function.
|
|
23
31
|
* Each table is granted read/write access and if exactly one table is provided,
|
|
@@ -51,7 +59,7 @@ export interface JaypieNextjsProps {
|
|
|
51
59
|
}
|
|
52
60
|
export declare class JaypieNextJs extends Construct {
|
|
53
61
|
private readonly _nextjs;
|
|
54
|
-
readonly domainName
|
|
62
|
+
readonly domainName?: string;
|
|
55
63
|
constructor(scope: Construct, id: string, props?: JaypieNextjsProps);
|
|
56
64
|
/** S3 bucket for static assets */
|
|
57
65
|
get bucket(): import("aws-cdk-lib/aws-s3").IBucket;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3217,13 +3217,19 @@ class JaypieMongoDbSecret extends JaypieEnvSecret {
|
|
|
3217
3217
|
class JaypieNextJs extends constructs.Construct {
|
|
3218
3218
|
constructor(scope, id, props) {
|
|
3219
3219
|
super(scope, id);
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3220
|
+
// Determine if we should use a custom domain
|
|
3221
|
+
const useDomain = props?.domainProps !== false;
|
|
3222
|
+
// Resolve domain name only if using a custom domain
|
|
3223
|
+
const domainName = useDomain
|
|
3224
|
+
? typeof props?.domainName === "string"
|
|
3225
|
+
? props.domainName
|
|
3226
|
+
: envHostname(props?.domainName)
|
|
3227
|
+
: undefined;
|
|
3223
3228
|
this.domainName = domainName;
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
.replace(/[^a-zA-Z0-9]/g, "_")
|
|
3229
|
+
// Use domain name or construct ID for cache policy naming
|
|
3230
|
+
const cachePolicyIdentifier = domainName
|
|
3231
|
+
? domainName.replace(/\./g, "-").replace(/[^a-zA-Z0-9]/g, "_")
|
|
3232
|
+
: id.replace(/[^a-zA-Z0-9]/g, "_");
|
|
3227
3233
|
// Resolve environment from array or object syntax
|
|
3228
3234
|
const environment = resolveEnvironment(props?.environment);
|
|
3229
3235
|
const envSecrets = props?.envSecrets || {};
|
|
@@ -3260,27 +3266,32 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
3260
3266
|
}, {});
|
|
3261
3267
|
const nextjs = new cdkNextjsStandalone.Nextjs(this, "NextJsApp", {
|
|
3262
3268
|
nextjsPath,
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
+
// Only configure custom domain if useDomain is true
|
|
3270
|
+
...(useDomain &&
|
|
3271
|
+
domainName && {
|
|
3272
|
+
domainProps: {
|
|
3273
|
+
domainName,
|
|
3274
|
+
hostedZone: resolveHostedZone(this, {
|
|
3275
|
+
zone: props?.hostedZone,
|
|
3276
|
+
}),
|
|
3277
|
+
},
|
|
3278
|
+
}),
|
|
3269
3279
|
environment: {
|
|
3270
3280
|
...jaypieLambdaEnv(),
|
|
3271
3281
|
...environment,
|
|
3272
3282
|
...secretsEnvironment,
|
|
3273
3283
|
...jaypieSecretsEnvironment,
|
|
3274
3284
|
...nextPublicEnv,
|
|
3275
|
-
NEXT_PUBLIC_SITE_URL
|
|
3285
|
+
// NEXT_PUBLIC_SITE_URL will be set after construct creation for CloudFront URL
|
|
3286
|
+
...(domainName && { NEXT_PUBLIC_SITE_URL: `https://${domainName}` }),
|
|
3276
3287
|
},
|
|
3277
3288
|
overrides: {
|
|
3278
3289
|
nextjsDistribution: {
|
|
3279
3290
|
imageCachePolicyProps: {
|
|
3280
|
-
cachePolicyName: `NextJsImageCachePolicy-${
|
|
3291
|
+
cachePolicyName: `NextJsImageCachePolicy-${cachePolicyIdentifier}`,
|
|
3281
3292
|
},
|
|
3282
3293
|
serverCachePolicyProps: {
|
|
3283
|
-
cachePolicyName: `NextJsServerCachePolicy-${
|
|
3294
|
+
cachePolicyName: `NextJsServerCachePolicy-${cachePolicyIdentifier}`,
|
|
3284
3295
|
},
|
|
3285
3296
|
},
|
|
3286
3297
|
nextjsImage: {
|
|
@@ -3295,6 +3306,10 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
3295
3306
|
},
|
|
3296
3307
|
},
|
|
3297
3308
|
});
|
|
3309
|
+
// Set NEXT_PUBLIC_SITE_URL to CloudFront URL when no custom domain
|
|
3310
|
+
if (!domainName) {
|
|
3311
|
+
nextjs.serverFunction.lambdaFunction.addEnvironment("NEXT_PUBLIC_SITE_URL", `https://${nextjs.distribution.distributionDomain}`);
|
|
3312
|
+
}
|
|
3298
3313
|
addDatadogLayers(nextjs.imageOptimizationFunction);
|
|
3299
3314
|
addDatadogLayers(nextjs.serverFunction.lambdaFunction);
|
|
3300
3315
|
// Grant secret read permissions
|