cdk-nextjs 0.7.11 → 0.7.13
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/.jsii +310 -100
- package/.jsii.tabl.json +1 -1
- package/API.md +211 -3
- package/README.md +116 -101
- package/docs/breaking-changes.md +36 -2
- package/docs/development-guide.md +10 -0
- package/docs/next-build-output-guide.md +1 -1
- package/lib/adapter/adapter.mjs +4 -1
- package/lib/generated-structs/OptionalNextjsDistributionProps.d.ts +21 -0
- package/lib/generated-structs/OptionalNextjsDistributionProps.js +1 -1
- package/lib/nextjs-api.js +1 -1
- package/lib/nextjs-build/nextjs-build.js +1 -1
- package/lib/nextjs-cache.js +1 -1
- package/lib/nextjs-compute/nextjs-containers.js +1 -1
- package/lib/nextjs-compute/nextjs-functions.js +1 -1
- package/lib/nextjs-distribution.d.ts +71 -2
- package/lib/nextjs-distribution.js +156 -107
- package/lib/nextjs-distribution.test.js +361 -12
- package/lib/nextjs-post-deploy.js +1 -1
- package/lib/nextjs-static-assets.d.ts +74 -5
- package/lib/nextjs-static-assets.js +276 -41
- package/lib/nextjs-static-assets.test.js +298 -1
- package/lib/root-constructs/nextjs-base-construct.d.ts +5 -4
- package/lib/root-constructs/nextjs-base-construct.js +17 -8
- package/lib/root-constructs/nextjs-global-containers.d.ts +16 -1
- package/lib/root-constructs/nextjs-global-containers.js +4 -2
- package/lib/root-constructs/nextjs-global-functions.d.ts +16 -1
- package/lib/root-constructs/nextjs-global-functions.js +4 -2
- package/lib/root-constructs/nextjs-regional-containers.js +1 -1
- package/lib/root-constructs/nextjs-regional-functions.js +1 -1
- package/lib/runtime/image-utils.d.ts +1 -0
- package/lib/runtime/image-utils.js +2 -1
- package/lib/runtime/image-utils.test.js +17 -1
- package/lib/runtime/image.js +5 -2
- package/lib/runtime/image.test.js +21 -1
- package/lib/runtime/lambda.mjs +9 -2
- package/lib/runtime/server.mjs +9 -2
- package/lib/utils/viewer-request-functions.d.ts +53 -0
- package/lib/utils/viewer-request-functions.js +172 -0
- package/lib/utils/viewer-request-functions.test.d.ts +1 -0
- package/lib/utils/viewer-request-functions.test.js +43 -0
- package/package.json +4 -1
- package/scripts/e2e-harness/app.js +7 -2
- package/scripts/render-diagrams.mjs +121 -0
|
@@ -42,7 +42,7 @@ We could ship this off to Lambda/Fargate and call it a day, but then we wouldn't
|
|
|
42
42
|
|
|
43
43
|
## S3
|
|
44
44
|
|
|
45
|
-
.next/static is simply copied to S3 and then CloudFront is configured to forward requests with paths match `\_next/static` or any paths in `public` folder to S3. `NextjsStaticAssets` is responsible for this. We also add S3 User Metadata with `BUILD_ID` to track which static files are apart of which deployment so we can prune later.
|
|
45
|
+
.next/static is simply copied to S3 and then CloudFront is configured to forward requests with paths match `\_next/static` or any paths in `public` folder to S3. `NextjsStaticAssets` is responsible for this. We also add S3 User Metadata with `BUILD_ID` to track which static files are apart of which deployment so we can prune later. The two trees are uploaded by separate `BucketDeployment`s so that `_next/static` objects get `Cache-Control: public, max-age=31536000, immutable`, the header Next.js itself sends for them (a third gives `_next/static/service-worker` the `public, max-age=0, must-revalidate` Next.js sends for a service worker, which keeps its URL across builds): CloudFront and API Gateway serve them straight from S3, so the object's metadata is the only `Cache-Control` a browser gets. `public` files keep their names when they change, so they get no header unless `overrides.nextjsStaticAssets.bucketDeploymentProps.cacheControl` sets one.
|
|
46
46
|
|
|
47
47
|
Note, with `NextjsRegionalContainers`, we unfortunately cannot configure ALB to forward static requests directly to S3 because the host header dictates which bucket you can route requests to and it's not reliable to manually name buckets based on your domain. Therefore, static assets are copied into the container image to be served in ECS Fargate.
|
|
48
48
|
|
package/lib/adapter/adapter.mjs
CHANGED
|
@@ -829,6 +829,8 @@ var require_package = __commonJS({
|
|
|
829
829
|
compat: "pnpm dlx projen compat",
|
|
830
830
|
compile: "pnpm dlx projen compile",
|
|
831
831
|
default: "pnpm dlx projen default",
|
|
832
|
+
diagrams: "pnpm dlx projen diagrams",
|
|
833
|
+
"diagrams:check": "pnpm dlx projen diagrams:check",
|
|
832
834
|
docgen: "pnpm dlx projen docgen",
|
|
833
835
|
eject: "pnpm dlx projen eject",
|
|
834
836
|
eslint: "pnpm dlx projen eslint",
|
|
@@ -866,6 +868,7 @@ var require_package = __commonJS({
|
|
|
866
868
|
"@aws-sdk/client-s3": "^3.1141.0",
|
|
867
869
|
"@aws-sdk/client-ssm": "^3.1141.0",
|
|
868
870
|
"@aws-sdk/lib-storage": "^3.1141.0",
|
|
871
|
+
"@iconify-json/logos": "1.2.16",
|
|
869
872
|
"@mrgrain/jsii-struct-builder": "^0.7.64",
|
|
870
873
|
"@next/routing": "16.4.0",
|
|
871
874
|
"@smithy/signature-v4": "^2.3.0",
|
|
@@ -948,7 +951,7 @@ var require_package = __commonJS({
|
|
|
948
951
|
publishConfig: {
|
|
949
952
|
access: "public"
|
|
950
953
|
},
|
|
951
|
-
version: "0.7.
|
|
954
|
+
version: "0.7.13",
|
|
952
955
|
packageManager: "pnpm@10.32.1",
|
|
953
956
|
jest: {
|
|
954
957
|
coverageProvider: "v8",
|
|
@@ -4,6 +4,27 @@ import type { NextjsType, PublicDirEntry } from '../';
|
|
|
4
4
|
* OptionalNextjsDistributionProps
|
|
5
5
|
*/
|
|
6
6
|
export interface OptionalNextjsDistributionProps {
|
|
7
|
+
/**
|
|
8
|
+
* A CloudFront KeyValueStore associated with every viewer-request function {@link viewerRequestFunctionCode} is copied into (up to three, one per kind of behavior), so values it reads — Basic auth credentials, an allowlist — live outside the CloudFormation template and change without a deploy.
|
|
9
|
+
* Read it with `cf.kvs()`, no ID needed.
|
|
10
|
+
* @default - none
|
|
11
|
+
* @stability stable
|
|
12
|
+
*/
|
|
13
|
+
readonly viewerRequestKeyValueStore?: aws_cloudfront.IKeyValueStore;
|
|
14
|
+
/**
|
|
15
|
+
* CloudFront Function code run first on every viewer request, on every behavior cdk-nextjs adds, static assets included — HTTP Basic auth on a pre-launch site, geo-gating.
|
|
16
|
+
* It must define `viewerRequest(event)` (a function, sync or async, or a
|
|
17
|
+
* `var`/`let`/`const`): return a response to answer the viewer, or the
|
|
18
|
+
* request (or nothing) to carry on. It is spliced into cdk-nextjs's own
|
|
19
|
+
* viewer-request functions, ahead of their logic, so it may not use the
|
|
20
|
+
* name `handler`, and the combined function must fit CloudFront's 10 KB.
|
|
21
|
+
* It runs on `cloudfront-js-2.0`, so it may be async and read
|
|
22
|
+
* {@link viewerRequestKeyValueStore} with `cf.kvs()`. A bring-your-own
|
|
23
|
+
* {@link distribution}'s default behavior isn't covered.
|
|
24
|
+
* @default - none
|
|
25
|
+
* @stability stable
|
|
26
|
+
*/
|
|
27
|
+
readonly viewerRequestFunctionCode?: aws_cloudfront.FunctionCode;
|
|
7
28
|
/**
|
|
8
29
|
* The most cache behaviors the distribution may have, the default one included.
|
|
9
30
|
* cdk-nextjs counts what it adds against this at synth, so running
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9uYWxOZXh0anNEaXN0cmlidXRpb25Qcm9wcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nZW5lcmF0ZWQtc3RydWN0cy9PcHRpb25hbE5leHRqc0Rpc3RyaWJ1dGlvblByb3BzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIvLyB+
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9uYWxOZXh0anNEaXN0cmlidXRpb25Qcm9wcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nZW5lcmF0ZWQtc3RydWN0cy9PcHRpb25hbE5leHRqc0Rpc3RyaWJ1dGlvblByb3BzLnRzIl0sIm5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lciBpdCwgYmVjYXVzZSB0aGF0IGlzIGhvdyBOZXh0LmpzXG4gICAqIGJ1aWxkcyB0aGUgVVJMLlxuICAgKiBAZGVmYXVsdCAtIG5vbmU7IHBhc3MgYE5leHRqc0J1aWxkLm5leHRDb25maWdBc3NldFByZWZpeFBhdGhgXG4gICAqIEBzdGFiaWxpdHkgc3RhYmxlXG4gICAqL1xuICByZWFkb25seSBhc3NldFByZWZpeD86IHN0cmluZztcbiAgLyoqXG4gICAqIEVudHJpZXMgKGZpbGVzL2RpcmVjdG9yaWVzKSB3aXRoaW4gTmV4dC5qcyBhcHAncyBwdWJsaWMgZGlyZWN0b3J5LiBVc2VkIHRvIGFkZCBzdGF0aWMgYmVoYXZpb3JzIHRvIGRpc3RyaWJ1dGlvbi5cbiAgICogQHN0YWJpbGl0eSBzdGFibGVcbiAgICovXG4gIHJlYWRvbmx5IHB1YmxpY0RpckVudHJpZXM/OiBBcnJheTxQdWJsaWNEaXJFbnRyeT47XG4gIC8qKlxuICAgKiBAc3RhYmlsaXR5IHN0YWJsZVxuICAgKi9cbiAgcmVhZG9ubHkgbmV4dGpzVHlwZT86IE5leHRqc1R5cGU7XG4gIC8qKlxuICAgKiBCdWNrZXQgY29udGFpbmluZyBzdGF0aWMgYXNzZXRzLlxuICAgKiBNdXN0IGJlIHByb3ZpZGVkIGlmIHlvdSB3YW50IHRvIHNlcnZlIHN0YXRpYyBmaWxlcy5cbiAgICogQHN0YWJpbGl0eSBzdGFibGVcbiAgICovXG4gIHJlYWRvbmx5IGFzc2V0c0J1Y2tldD86IGF3c19zMy5JQnVja2V0O1xufVxuIl19
|
package/lib/nextjs-api.js
CHANGED
|
@@ -22,7 +22,7 @@ const API_PATH_PART = /^[a-zA-Z0-9:._\-$]+$/;
|
|
|
22
22
|
* Creates an API Gateway REST API for Next.js applications
|
|
23
23
|
*/
|
|
24
24
|
class NextjsApi extends constructs_1.Construct {
|
|
25
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsApi", version: "0.7.
|
|
25
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsApi", version: "0.7.13" };
|
|
26
26
|
/**
|
|
27
27
|
* The API Gateway REST API
|
|
28
28
|
*/
|
|
@@ -66,7 +66,7 @@ function deploymentArchitecture(props) {
|
|
|
66
66
|
* @link https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
|
67
67
|
*/
|
|
68
68
|
class NextjsBuild extends constructs_1.Construct {
|
|
69
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsBuild", version: "0.7.
|
|
69
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsBuild", version: "0.7.13" };
|
|
70
70
|
/**
|
|
71
71
|
* Unique id for this deployment. Used to partition cache storage and as
|
|
72
72
|
* metadata for static assets in S3 bucket.
|
package/lib/nextjs-cache.js
CHANGED
|
@@ -86,7 +86,7 @@ function sizeOfDirectory(dir) {
|
|
|
86
86
|
* Next.js Cache construct providing unified S3 and DynamoDB cache management.
|
|
87
87
|
*/
|
|
88
88
|
class NextjsCache extends constructs_1.Construct {
|
|
89
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsCache", version: "0.7.
|
|
89
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsCache", version: "0.7.13" };
|
|
90
90
|
cacheBucket;
|
|
91
91
|
revalidationTable;
|
|
92
92
|
buildId;
|
|
@@ -19,7 +19,7 @@ const constants_1 = require("../constants");
|
|
|
19
19
|
* Fargate.
|
|
20
20
|
*/
|
|
21
21
|
class NextjsContainers extends constructs_1.Construct {
|
|
22
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsContainers", version: "0.7.
|
|
22
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsContainers", version: "0.7.13" };
|
|
23
23
|
albFargateService;
|
|
24
24
|
ecsCluster;
|
|
25
25
|
url;
|
|
@@ -23,7 +23,7 @@ const zip_directory_1 = require("../utils/zip-directory");
|
|
|
23
23
|
* `awslambda.streamifyResponse` directly.
|
|
24
24
|
*/
|
|
25
25
|
class NextjsFunctions extends constructs_1.Construct {
|
|
26
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsFunctions", version: "0.7.
|
|
26
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-nextjs.NextjsFunctions", version: "0.7.13" };
|
|
27
27
|
/**
|
|
28
28
|
* The `default` group's function: the one the distribution's default behavior
|
|
29
29
|
* targets, and the only one at all unless `functionGroups` is used.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
2
|
-
import { AddBehaviorOptions, CachePolicyProps, Distribution, ResponseHeadersPolicyProps } from "aws-cdk-lib/aws-cloudfront";
|
|
2
|
+
import { AddBehaviorOptions, CachePolicyProps, Distribution, FunctionCode, IKeyValueStore, ResponseHeadersPolicyProps } from "aws-cdk-lib/aws-cloudfront";
|
|
3
3
|
import { FunctionUrlOriginWithOACProps, VpcOriginWithEndpointProps } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
4
4
|
import { IApplicationLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";
|
|
5
5
|
import { IFunctionUrl } from "aws-cdk-lib/aws-lambda";
|
|
@@ -101,6 +101,34 @@ export interface NextjsDistributionProps {
|
|
|
101
101
|
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html#limits-web-distributions
|
|
102
102
|
*/
|
|
103
103
|
readonly maxCacheBehaviors?: number;
|
|
104
|
+
/**
|
|
105
|
+
* CloudFront Function code run first on every viewer request, on every
|
|
106
|
+
* behavior cdk-nextjs adds, static assets included — HTTP Basic auth on a
|
|
107
|
+
* pre-launch site, geo-gating.
|
|
108
|
+
*
|
|
109
|
+
* It must define `viewerRequest(event)` (a function, sync or async, or a
|
|
110
|
+
* `var`/`let`/`const`): return a response to answer the viewer, or the
|
|
111
|
+
* request (or nothing) to carry on. It is spliced into cdk-nextjs's own
|
|
112
|
+
* viewer-request functions, ahead of their logic, so it may not use the
|
|
113
|
+
* name `handler`, and the combined function must fit CloudFront's 10 KB.
|
|
114
|
+
* It runs on `cloudfront-js-2.0`, so it may be async and read
|
|
115
|
+
* {@link viewerRequestKeyValueStore} with `cf.kvs()`. A bring-your-own
|
|
116
|
+
* {@link distribution}'s default behavior isn't covered.
|
|
117
|
+
*
|
|
118
|
+
* @default - none
|
|
119
|
+
* @see https://github.com/cdklabs/cdk-nextjs#running-code-on-every-viewer-request
|
|
120
|
+
*/
|
|
121
|
+
readonly viewerRequestFunctionCode?: FunctionCode;
|
|
122
|
+
/**
|
|
123
|
+
* A CloudFront KeyValueStore associated with every viewer-request function
|
|
124
|
+
* {@link viewerRequestFunctionCode} is copied into (up to three, one per kind
|
|
125
|
+
* of behavior), so values it reads — Basic auth credentials, an allowlist —
|
|
126
|
+
* live outside the CloudFormation template and change without a deploy.
|
|
127
|
+
* Read it with `cf.kvs()`, no ID needed.
|
|
128
|
+
* @default - none
|
|
129
|
+
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-custom-methods.html
|
|
130
|
+
*/
|
|
131
|
+
readonly viewerRequestKeyValueStore?: IKeyValueStore;
|
|
104
132
|
}
|
|
105
133
|
/** A non-default function group and the origin its routes must reach. */
|
|
106
134
|
export interface NextjsDistributionFunctionGroup {
|
|
@@ -134,6 +162,18 @@ export declare class NextjsDistribution extends Construct {
|
|
|
134
162
|
private dynamicOrigin;
|
|
135
163
|
private dynamicOriginResponsePolicy;
|
|
136
164
|
private dynamicCloudFrontFunctionAssociations;
|
|
165
|
+
/**
|
|
166
|
+
* `viewerRequestFunctionCode`, rendered and checked once, since
|
|
167
|
+
* `FunctionCode.fromFile` reads the file on every render.
|
|
168
|
+
*/
|
|
169
|
+
private viewerRequestCode?;
|
|
170
|
+
/**
|
|
171
|
+
* The viewer-request function `viewerRequestFunctionCode` adds to behaviors
|
|
172
|
+
* with no viewer-request logic of their own, shared by all of them, so the
|
|
173
|
+
* `assetPrefix` behavior, which has a viewer-request function of its own,
|
|
174
|
+
* can tell it from an override's.
|
|
175
|
+
*/
|
|
176
|
+
private passThroughFunction?;
|
|
137
177
|
private isFunctionCompute;
|
|
138
178
|
private staticBehaviorOptions;
|
|
139
179
|
private dynamicBehaviorOptions;
|
|
@@ -168,11 +208,40 @@ export declare class NextjsDistribution extends Construct {
|
|
|
168
208
|
* @see https://open-next.js.org/advanced/workaround#workaround-set-x-forwarded-host-header-aws-specific
|
|
169
209
|
*/
|
|
170
210
|
private createDynamicCloudFrontFunctionAssociations;
|
|
211
|
+
/**
|
|
212
|
+
* The function a behavior with no viewer-request logic of its own gets when
|
|
213
|
+
* `viewerRequestFunctionCode` is set, created on first use.
|
|
214
|
+
*/
|
|
215
|
+
private getPassThroughFunction;
|
|
216
|
+
/**
|
|
217
|
+
* The code, runtime and KeyValueStore of a function whose `handler` is
|
|
218
|
+
* cdk-nextjs's, with `viewerRequestFunctionCode` spliced in
|
|
219
|
+
* ({@link spliceViewerRequest}) and checked against CloudFront's size limit.
|
|
220
|
+
*
|
|
221
|
+
* Every one runs on `cloudfront-js-2.0`, the runtime AWS recommends and the
|
|
222
|
+
* one with `async` and KeyValueStores, so the handlers are all `async`
|
|
223
|
+
* whether or not there is user code to await.
|
|
224
|
+
*/
|
|
225
|
+
private viewerRequestFunctionProps;
|
|
226
|
+
/**
|
|
227
|
+
* `viewerRequestFunctionCode`, rendered once, since `FunctionCode.fromFile`
|
|
228
|
+
* reads the file on every render, and checked
|
|
229
|
+
* ({@link checkViewerRequestCode}).
|
|
230
|
+
*/
|
|
231
|
+
private renderViewerRequestCode;
|
|
232
|
+
/**
|
|
233
|
+
* CloudFront allows one function per event type per behavior, so an
|
|
234
|
+
* override's viewer-request association and one cdk-nextjs needs can't both
|
|
235
|
+
* be kept. Thrown at synth, where both halves are known, rather than left to
|
|
236
|
+
* a deploy that names neither.
|
|
237
|
+
*/
|
|
238
|
+
private assertViewerRequestUnclaimed;
|
|
171
239
|
private createStaticBehaviorOptions;
|
|
172
240
|
private createDynamicBehaviorOptions;
|
|
173
241
|
/**
|
|
174
242
|
* The behavior's function associations: an override's, plus the viewer-request
|
|
175
|
-
* function Global Functions depends on
|
|
243
|
+
* function Global Functions depends on, or the one `viewerRequestFunctionCode`
|
|
244
|
+
* adds on Global Containers.
|
|
176
245
|
*
|
|
177
246
|
* Spreading the override's `functionAssociations` over ours would silently
|
|
178
247
|
* drop that function, and with it the only thing standing between a viewer's
|