cdk-nextjs 0.7.12 → 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 +237 -81
- package/.jsii.tabl.json +1 -1
- package/API.md +152 -0
- package/README.md +115 -100
- package/docs/breaking-changes.md +4 -2
- package/docs/development-guide.md +10 -0
- 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.js +1 -1
- package/lib/nextjs-static-assets.test.js +19 -7
- package/lib/root-constructs/nextjs-base-construct.js +1 -1
- 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/lambda.mjs +4 -1
- package/lib/runtime/server.mjs +4 -1
- 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
package/README.md
CHANGED
|
@@ -36,6 +36,17 @@ Deploy [Next.js](https://nextjs.org/) apps on [AWS](https://aws.amazon.com/) wit
|
|
|
36
36
|
- [Bring Your Own Resources](#bring-your-own-resources) — import existing AWS resources (CloudFront distributions, ECS clusters, ALBs, S3 buckets, DynamoDB tables).
|
|
37
37
|
- [AWS GovCloud (US)](https://aws.amazon.com/govcloud-us) compatible with `NextjsRegionalFunctions` and `NextjsRegionalContainers`.
|
|
38
38
|
|
|
39
|
+
## Why
|
|
40
|
+
|
|
41
|
+
The simplest path to deploy Next.js is on [Vercel](https://vercel.com/) - the Platform-as-a-Service company behind Next.js. However, deploying to Vercel can be expensive and some developers want all of their workloads running _directly_ on AWS. Developers can deploy Next.js on AWS through [AWS Amplify Hosting](https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplifysupport.html), but Amplify does not support all Next.js features and manages AWS resources for you so they cannot be customized. If Amplify meets your requirements we recommend you use it, but if you want to use all Next.js features or want more visibility into the AWS resources then this construct is for you.
|
|
42
|
+
|
|
43
|
+
## Design Principles
|
|
44
|
+
|
|
45
|
+
- Integrate through Next.js's official interfaces. Build on the [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters) API and [`@next/routing`](https://www.npmjs.com/package/@next/routing) rather than Next.js internals, so new Next.js versions rarely break this construct. Where no public interface exists yet, the dependency is listed in [Next.js private APIs](docs/nextjs-private-apis.md).
|
|
46
|
+
- Security first.
|
|
47
|
+
- One architecture does not fit all.
|
|
48
|
+
- Enable customization everywhere.
|
|
49
|
+
|
|
39
50
|
## Prerequisites
|
|
40
51
|
|
|
41
52
|
- Next.js app running v16.3 or higher (`next build` fails on older versions). If you don't have one yet - follow [these steps](https://nextjs.org/docs/getting-started) to create one.
|
|
@@ -102,6 +113,34 @@ new WebStack(app, "web-stack");
|
|
|
102
113
|
|
|
103
114
|
See [examples/](./examples/) for more usage examples.
|
|
104
115
|
|
|
116
|
+
## Architecture
|
|
117
|
+
|
|
118
|
+
How requests are served inside the compute — the adapter runtime, and where it deliberately differs from `next start` — is in [docs/adapter-runtime.md](./docs/adapter-runtime.md).
|
|
119
|
+
|
|
120
|
+
### `NextjsGlobalFunctions`
|
|
121
|
+
|
|
122
|
+
Architecture includes [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) Functions to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this construct when you have unpredictable traffic, can afford occasional latency (i.e. cold starts - [typically 1% of production traffic](https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/)), and/or want the most granular pricing model. ([code](./src/root-constructs/nextjs-global-functions.ts))
|
|
123
|
+
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
### `NextjsGlobalContainers`
|
|
127
|
+
|
|
128
|
+
Architecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this option when you have predictable traffic, need the lowest latency, and/or can afford a less granular pricing model. ([code](./src/root-constructs/nextjs-global-containers.ts))
|
|
129
|
+
|
|
130
|
+

|
|
131
|
+
|
|
132
|
+
### `NextjsRegionalContainers`
|
|
133
|
+
|
|
134
|
+
Architecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/) to regionally serve requests. Use this options when you cannot use Amazon CloudFront (i.e. [AWS GovCloud](https://aws.amazon.com/govcloud-us/?whats-new.sort-by=item.additionalFields.postDateTime&whats-new.sort-order=desc)). ([code](./src/root-constructs/nextjs-regional-containers.ts#L41))
|
|
135
|
+
|
|
136
|
+

|
|
137
|
+
|
|
138
|
+
### `NextjsRegionalFunctions`
|
|
139
|
+
|
|
140
|
+
Architecture includes [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) Functions to respond to dynamic requests and [API Gateway REST API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html) to regionally serve requests and distribute static assets. Use this options when you cannot use Amazon CloudFront (i.e. [AWS GovCloud](https://aws.amazon.com/govcloud-us/?whats-new.sort-by=item.additionalFields.postDateTime&whats-new.sort-order=desc)). ([code](./src/root-constructs/nextjs-regional-functions.ts))
|
|
141
|
+
|
|
142
|
+

|
|
143
|
+
|
|
105
144
|
## Configuration
|
|
106
145
|
|
|
107
146
|
The variables below are read at runtime by the cache handler inside your deployed
|
|
@@ -415,114 +454,90 @@ Notes:
|
|
|
415
454
|
- Per-group `overrides` let you size each function independently:
|
|
416
455
|
`{ name: "reports", routes: [...], overrides: { functionProps: { memorySize: 2048 } } }`.
|
|
417
456
|
|
|
418
|
-
##
|
|
457
|
+
## Running Code on Every Viewer Request
|
|
419
458
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
```mermaid
|
|
427
|
-
architecture-beta
|
|
428
|
-
group aws(cloud)[AWS Cloud]
|
|
429
|
-
group cache[Cache Layer] in aws
|
|
430
|
-
|
|
431
|
-
service user(internet)[User]
|
|
432
|
-
service cloudfront(server)[CloudFront Distribution] in aws
|
|
433
|
-
service s3static(disk)[S3 Static Assets] in aws
|
|
434
|
-
service lambda(server)[Lambda Function] in aws
|
|
435
|
-
service dynamodb(database)[DynamoDB Table] in cache
|
|
436
|
-
service s3cache(disk)[S3 Cache Bucket] in cache
|
|
437
|
-
|
|
438
|
-
user:R --> L:cloudfront
|
|
439
|
-
cloudfront:R --> L:s3static
|
|
440
|
-
cloudfront:R --> L:lambda
|
|
441
|
-
lambda:R --> L:dynamodb
|
|
442
|
-
lambda:R --> L:s3cache
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
### `NextjsGlobalContainers`
|
|
446
|
-
|
|
447
|
-
Architecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this option when you have predictable traffic, need the lowest latency, and/or can afford a less granular pricing model. ([code](./src/root-constructs/nextjs-global-containers.ts))
|
|
448
|
-
|
|
449
|
-
```mermaid
|
|
450
|
-
architecture-beta
|
|
451
|
-
group aws(cloud)[AWS Cloud]
|
|
452
|
-
group vpc[VPC] in aws
|
|
453
|
-
group cache[Cache Layer] in aws
|
|
454
|
-
|
|
455
|
-
service user(internet)[User]
|
|
456
|
-
service cloudfront(server)[CloudFront Distribution] in aws
|
|
457
|
-
service s3static(disk)[S3 Static Assets] in aws
|
|
458
|
-
service alb(server)[Application Load Balancer] in vpc
|
|
459
|
-
service fargate(server)[ECS Fargate Containers] in vpc
|
|
460
|
-
service dynamodb(database)[DynamoDB Table] in cache
|
|
461
|
-
service s3cache(disk)[S3 Cache Bucket] in cache
|
|
462
|
-
|
|
463
|
-
user:R --> L:cloudfront
|
|
464
|
-
cloudfront:R --> L:s3static
|
|
465
|
-
cloudfront:R --> L:alb
|
|
466
|
-
alb:R --> L:fargate
|
|
467
|
-
fargate:R --> L:dynamodb
|
|
468
|
-
fargate:R --> L:s3cache
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
### `NextjsRegionalContainers`
|
|
459
|
+
`NextjsGlobalFunctions` and `NextjsGlobalContainers` take a
|
|
460
|
+
`viewerRequestFunctionCode` prop: CloudFront Function code that runs first on
|
|
461
|
+
every request, on every behavior cdk-nextjs adds — pages, API routes,
|
|
462
|
+
`_next/image`, `_next/static` and `public/` files alike. It's the place for a
|
|
463
|
+
gate the whole site has to pass, such as HTTP Basic auth before launch:
|
|
472
464
|
|
|
473
|
-
|
|
465
|
+
```ts
|
|
466
|
+
import { FunctionCode, KeyValueStore } from "aws-cdk-lib/aws-cloudfront";
|
|
474
467
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
468
|
+
const credentials = new KeyValueStore(this, "Credentials");
|
|
469
|
+
new NextjsGlobalFunctions(this, "Nextjs", {
|
|
470
|
+
buildDirectory: join(import.meta.dirname),
|
|
471
|
+
viewerRequestKeyValueStore: credentials,
|
|
472
|
+
viewerRequestFunctionCode: FunctionCode.fromInline(`
|
|
473
|
+
import cf from "cloudfront";
|
|
474
|
+
const kvs = cf.kvs();
|
|
475
|
+
async function viewerRequest(event) {
|
|
476
|
+
const auth = event.request.headers.authorization;
|
|
477
|
+
try {
|
|
478
|
+
if (auth && auth.value === "Basic " + (await kvs.get("basic-auth"))) {
|
|
479
|
+
// verified: don't pass the site's credentials on to the origin
|
|
480
|
+
delete event.request.headers.authorization;
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
} catch (e) {
|
|
484
|
+
// no "basic-auth" key yet: stay locked
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
statusCode: 401,
|
|
488
|
+
statusDescription: "Unauthorized",
|
|
489
|
+
headers: { "www-authenticate": { value: 'Basic realm="preview"' } },
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
`),
|
|
493
|
+
});
|
|
491
494
|
```
|
|
492
495
|
|
|
493
|
-
|
|
496
|
+
Then put the credentials in the store, outside the template:
|
|
494
497
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
service user(internet)[User]
|
|
503
|
-
service apigateway(server)[API Gateway REST API] in aws
|
|
504
|
-
service s3static(disk)[S3 Static Assets] in aws
|
|
505
|
-
service lambda(server)[Lambda Function] in aws
|
|
506
|
-
service dynamodb(database)[DynamoDB Table] in cache
|
|
507
|
-
service s3cache(disk)[S3 Cache Bucket] in cache
|
|
508
|
-
|
|
509
|
-
user:R --> L:apigateway
|
|
510
|
-
apigateway:R --> L:s3static
|
|
511
|
-
apigateway:R --> L:lambda
|
|
512
|
-
lambda:R --> L:dynamodb
|
|
513
|
-
lambda:R --> L:s3cache
|
|
498
|
+
```sh
|
|
499
|
+
KVS_ARN=... # the store's ARN
|
|
500
|
+
aws cloudfront-keyvaluestore put-key --kvs-arn "$KVS_ARN" \
|
|
501
|
+
--key basic-auth --value "$(printf 'user:pass' | base64 | tr -d '\n')" \
|
|
502
|
+
--if-match "$(aws cloudfront-keyvaluestore describe-key-value-store \
|
|
503
|
+
--kvs-arn "$KVS_ARN" --query ETag --output text)"
|
|
514
504
|
```
|
|
515
505
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
-
|
|
524
|
-
-
|
|
525
|
-
-
|
|
506
|
+
The code must define `viewerRequest(event)`, as a function (`async` or not)
|
|
507
|
+
or a `var`/`let`/`const`. It's a CloudFront Function handler in all but name:
|
|
508
|
+
return a response to answer the viewer, or the request (or nothing) to carry
|
|
509
|
+
on.
|
|
510
|
+
|
|
511
|
+
Why not a function of your own on viewer-request? CloudFront allows one per
|
|
512
|
+
event type per behavior, and on Global Functions cdk-nextjs's own one
|
|
513
|
+
overwrites `X-Forwarded-Host` and redirects repeated slashes. So your code is
|
|
514
|
+
spliced into that function, ahead of cdk-nextjs's logic, which still runs after
|
|
515
|
+
it, so your code can't undo the `X-Forwarded-Host` overwrite. Middleware can't
|
|
516
|
+
do this instead: on Global Functions CloudFront signs the request to the
|
|
517
|
+
Function URL with the `Authorization` header, and static assets never reach the
|
|
518
|
+
server at all.
|
|
519
|
+
|
|
520
|
+
- cdk-nextjs's CloudFront Functions run on `cloudfront-js-2.0`, so your code
|
|
521
|
+
can be `async`, and `import cf from "cloudfront"` works when it comes first,
|
|
522
|
+
as it does above.
|
|
523
|
+
- `viewerRequestKeyValueStore` is associated with every viewer-request function
|
|
524
|
+
your code is copied into (up to three, one per kind of behavior), so
|
|
525
|
+
`cf.kvs()` reads it with no ID wherever the code runs. Credentials written
|
|
526
|
+
inline in the code instead end up in the CloudFormation template.
|
|
527
|
+
- The combined function, cdk-nextjs's code included, must fit CloudFront's
|
|
528
|
+
10 KB limit; synth fails if it doesn't (or warns, if the code contains a
|
|
529
|
+
CDK token, whose size isn't known until deploy).
|
|
530
|
+
- Your code shares the file with cdk-nextjs's `handler`, so it can't use the
|
|
531
|
+
name `handler` at all, even in a comment or a string; synth refuses it.
|
|
532
|
+
- A viewer-request association in `overrides.*BehaviorOptions.functionAssociations`
|
|
533
|
+
on a behavior this covers is refused at synth; put that logic in
|
|
534
|
+
`viewerRequestFunctionCode` instead. So is
|
|
535
|
+
`overrides.distributionProps.defaultBehavior` without a `basePath`, since it
|
|
536
|
+
would replace the default behavior the code runs on; customize it through
|
|
537
|
+
`overrides.dynamicBehaviorOptions`.
|
|
538
|
+
- A bring-your-own `distribution`'s default behavior is yours, so it isn't
|
|
539
|
+
covered. Only the behaviors cdk-nextjs adds are; under a `basePath`, those
|
|
540
|
+
include the ones that stand in for the default behavior.
|
|
526
541
|
|
|
527
542
|
## Bring Your Own Resources
|
|
528
543
|
|
package/docs/breaking-changes.md
CHANGED
|
@@ -447,8 +447,10 @@ absolute URLs, cached for other viewers). Now:
|
|
|
447
447
|
|
|
448
448
|
- associations on other event types (viewer-response, say) are added next to it;
|
|
449
449
|
- an association on viewer-request throws at synth, since CloudFront allows one
|
|
450
|
-
function per event type per behavior. Move that logic
|
|
451
|
-
|
|
450
|
+
function per event type per behavior. Move that logic into the
|
|
451
|
+
`viewerRequestFunctionCode` prop, which runs it inside cdk-nextjs's own
|
|
452
|
+
viewer-request function on every behavior, static assets included (see
|
|
453
|
+
[Running Code on Every Viewer Request](../README.md#running-code-on-every-viewer-request)).
|
|
452
454
|
|
|
453
455
|
The runtime trusts `X-Forwarded-Host` only on a request Lambda reports as
|
|
454
456
|
IAM-authenticated, so a Function URL overridden to `authType: NONE` builds its
|
|
@@ -66,3 +66,13 @@ Both `build` and `dev` chain it explicitly (`npm run sync-cdk-nextjs && next …
|
|
|
66
66
|
For iterative development, just run `pnpm build` from the root to rebuild the adapter, then `pnpm build` in the example app—the sync step will copy the latest version.
|
|
67
67
|
|
|
68
68
|
Note that `pnpm install` recreates the `link:../..` symlink, so always go through `pnpm build` / `pnpm dev`. Invoking `next build` or `next dev` directly skips the sync and Turbopack then fails on the symlinked path, e.g. `FileSystemPath("app-playground").join("./../../lib/adapter/cache-handler.mjs") leaves the filesystem root`.
|
|
69
|
+
|
|
70
|
+
## Architecture Diagrams
|
|
71
|
+
|
|
72
|
+
The README's architecture diagrams are Mermaid [`architecture-beta`](https://mermaid.js.org/syntax/architecture.html) sources in [`docs/diagrams/`](./diagrams/), rendered to SVG with AWS icons from the Iconify [`logos`](https://icon-sets.iconify.design/logos/?keyword=aws) set (`logos:aws-lambda`, `logos:aws-cloudfront`, ...). After editing a `.mmd` file:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pnpm diagrams
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Commit the `.mmd` and the regenerated `.svg` together. `pnpm test` fails if an SVG is stale against its source. The README links the SVGs on `main`, so a PR's README preview shows the old diagrams until it merges; open the SVG in the PR's files view to see the new one.
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9uYWxOZXh0anNEaXN0cmlidXRpb25Qcm9wcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nZW5lcmF0ZWQtc3RydWN0cy9PcHRpb25hbE5leHRqc0Rpc3RyaWJ1dGlvblByb3BzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIvLyB+fiBHZW5lcmF0ZWQgYnkgcHJvamVuLiBUbyBtb2RpZnksIGVka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hc3MgYE5leHRqc0J1aWxkLm5leHRDb25maWdBc3NldFByZWZpeFBhdGhgXG4gICAqIEBzdGFiaWxpdHkgc3RhYmxlXG4gICAqL1xuICByZWFkb25seSBhc3NldFByZWZpeD86IHN0cmluZztcbiAgLyoqXG4gICAqIEVudHJpZXMgKGZpbGVzL2RpcmVjdG9yaWVzKSB3aXRoaW4gTmV4dC5qcyBhcHAncyBwdWJsaWMgZGlyZWN0b3J5LiBVc2VkIHRvIGFkZCBzdGF0aWMgYmVoYXZpb3JzIHRvIGRpc3RyaWJ1dGlvbi5cbiAgICogQHN0YWJpbGl0eSBzdGFibGVcbiAgICovXG4gIHJlYWRvbmx5IHB1YmxpY0RpckVudHJpZXM/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
|