@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/esm/index.js
CHANGED
|
@@ -3185,13 +3185,19 @@ class JaypieMongoDbSecret extends JaypieEnvSecret {
|
|
|
3185
3185
|
class JaypieNextJs extends Construct {
|
|
3186
3186
|
constructor(scope, id, props) {
|
|
3187
3187
|
super(scope, id);
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3188
|
+
// Determine if we should use a custom domain
|
|
3189
|
+
const useDomain = props?.domainProps !== false;
|
|
3190
|
+
// Resolve domain name only if using a custom domain
|
|
3191
|
+
const domainName = useDomain
|
|
3192
|
+
? typeof props?.domainName === "string"
|
|
3193
|
+
? props.domainName
|
|
3194
|
+
: envHostname(props?.domainName)
|
|
3195
|
+
: undefined;
|
|
3191
3196
|
this.domainName = domainName;
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
.replace(/[^a-zA-Z0-9]/g, "_")
|
|
3197
|
+
// Use domain name or construct ID for cache policy naming
|
|
3198
|
+
const cachePolicyIdentifier = domainName
|
|
3199
|
+
? domainName.replace(/\./g, "-").replace(/[^a-zA-Z0-9]/g, "_")
|
|
3200
|
+
: id.replace(/[^a-zA-Z0-9]/g, "_");
|
|
3195
3201
|
// Resolve environment from array or object syntax
|
|
3196
3202
|
const environment = resolveEnvironment(props?.environment);
|
|
3197
3203
|
const envSecrets = props?.envSecrets || {};
|
|
@@ -3228,27 +3234,32 @@ class JaypieNextJs extends Construct {
|
|
|
3228
3234
|
}, {});
|
|
3229
3235
|
const nextjs = new Nextjs(this, "NextJsApp", {
|
|
3230
3236
|
nextjsPath,
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
+
// Only configure custom domain if useDomain is true
|
|
3238
|
+
...(useDomain &&
|
|
3239
|
+
domainName && {
|
|
3240
|
+
domainProps: {
|
|
3241
|
+
domainName,
|
|
3242
|
+
hostedZone: resolveHostedZone(this, {
|
|
3243
|
+
zone: props?.hostedZone,
|
|
3244
|
+
}),
|
|
3245
|
+
},
|
|
3246
|
+
}),
|
|
3237
3247
|
environment: {
|
|
3238
3248
|
...jaypieLambdaEnv(),
|
|
3239
3249
|
...environment,
|
|
3240
3250
|
...secretsEnvironment,
|
|
3241
3251
|
...jaypieSecretsEnvironment,
|
|
3242
3252
|
...nextPublicEnv,
|
|
3243
|
-
NEXT_PUBLIC_SITE_URL
|
|
3253
|
+
// NEXT_PUBLIC_SITE_URL will be set after construct creation for CloudFront URL
|
|
3254
|
+
...(domainName && { NEXT_PUBLIC_SITE_URL: `https://${domainName}` }),
|
|
3244
3255
|
},
|
|
3245
3256
|
overrides: {
|
|
3246
3257
|
nextjsDistribution: {
|
|
3247
3258
|
imageCachePolicyProps: {
|
|
3248
|
-
cachePolicyName: `NextJsImageCachePolicy-${
|
|
3259
|
+
cachePolicyName: `NextJsImageCachePolicy-${cachePolicyIdentifier}`,
|
|
3249
3260
|
},
|
|
3250
3261
|
serverCachePolicyProps: {
|
|
3251
|
-
cachePolicyName: `NextJsServerCachePolicy-${
|
|
3262
|
+
cachePolicyName: `NextJsServerCachePolicy-${cachePolicyIdentifier}`,
|
|
3252
3263
|
},
|
|
3253
3264
|
},
|
|
3254
3265
|
nextjsImage: {
|
|
@@ -3263,6 +3274,10 @@ class JaypieNextJs extends Construct {
|
|
|
3263
3274
|
},
|
|
3264
3275
|
},
|
|
3265
3276
|
});
|
|
3277
|
+
// Set NEXT_PUBLIC_SITE_URL to CloudFront URL when no custom domain
|
|
3278
|
+
if (!domainName) {
|
|
3279
|
+
nextjs.serverFunction.lambdaFunction.addEnvironment("NEXT_PUBLIC_SITE_URL", `https://${nextjs.distribution.distributionDomain}`);
|
|
3280
|
+
}
|
|
3266
3281
|
addDatadogLayers(nextjs.imageOptimizationFunction);
|
|
3267
3282
|
addDatadogLayers(nextjs.serverFunction.lambdaFunction);
|
|
3268
3283
|
// Grant secret read permissions
|