cdk-nextjs 0.6.2 → 0.7.0
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 +2404 -2723
- package/.jsii.tabl.json +1 -1
- package/API.md +1681 -1930
- package/CLAUDE.md +2 -1
- package/README.md +429 -130
- package/assets/lambdas/post-deploy/post-deploy.lambda/index.js +148 -169
- package/assets/lambdas/redeploy-stage/redeploy-stage.lambda/index.js +875 -0
- package/docs/adapter-runtime.md +185 -0
- package/docs/breaking-changes.md +667 -4
- package/docs/caching-guide.md +156 -112
- package/docs/cdk-nextjs-cfn-exec-policy.json +2 -1
- package/docs/development-guide.md +1 -1
- package/docs/harness-coverage.md +598 -0
- package/docs/init-cache-deployment.md +32 -1
- package/docs/next-build-output-guide.md +30 -20
- package/examples/README.md +5 -1
- package/lib/adapter/__fixtures__/app-playground-base-path.json +4926 -0
- package/lib/adapter/__fixtures__/app-playground.json +4917 -0
- package/lib/adapter/__fixtures__/pages-i18n.json +1728 -0
- package/lib/adapter/adapter.mjs +1548 -185
- package/lib/adapter/adapter.test.js +106 -0
- package/lib/adapter/aws-cache-store.d.ts +489 -0
- package/lib/adapter/aws-cache-store.js +1004 -0
- package/lib/adapter/aws-cache-store.test.d.ts +1 -0
- package/lib/adapter/aws-cache-store.test.js +361 -0
- package/lib/adapter/build-outputs.d.ts +80 -0
- package/lib/adapter/build-outputs.js +852 -0
- package/lib/adapter/build-outputs.test.d.ts +1 -0
- package/lib/adapter/build-outputs.test.js +861 -0
- package/lib/adapter/cache-handler.d.ts +9 -2
- package/lib/adapter/cache-handler.js +72 -96
- package/lib/adapter/cache-handler.mjs +18956 -17774
- package/lib/adapter/cache-handler.test.js +263 -31
- package/lib/adapter/cache-kinds.d.ts +32 -0
- package/lib/adapter/cache-kinds.js +35 -0
- package/lib/adapter/cache-kinds.test.d.ts +1 -0
- package/lib/adapter/cache-kinds.test.js +69 -0
- package/lib/adapter/cache-utils.d.ts +90 -0
- package/lib/adapter/cache-utils.js +199 -4
- package/lib/adapter/cache-utils.test.d.ts +1 -0
- package/lib/adapter/cache-utils.test.js +179 -0
- package/lib/adapter/function-groups.d.ts +215 -0
- package/lib/adapter/function-groups.js +1099 -0
- package/lib/adapter/function-groups.test.d.ts +1 -0
- package/lib/adapter/function-groups.test.js +743 -0
- package/lib/adapter/init-cache.d.ts +6 -0
- package/lib/adapter/init-cache.js +245 -0
- package/lib/adapter/init-cache.test.d.ts +1 -0
- package/lib/adapter/init-cache.test.js +137 -0
- package/lib/adapter/local-file-cache-handler.d.ts +23 -0
- package/lib/adapter/local-file-cache-handler.js +52 -1
- package/lib/adapter/memory-cache-handler.d.ts +26 -17
- package/lib/adapter/memory-cache-handler.js +32 -50
- package/lib/adapter/memory-cache-handler.test.js +105 -85
- package/lib/adapter/s3-cache-handler.d.ts +179 -40
- package/lib/adapter/s3-cache-handler.js +807 -277
- package/lib/adapter/s3-cache-handler.test.js +1186 -31
- package/lib/adapter/use-cache-common.d.ts +90 -0
- package/lib/adapter/use-cache-common.js +250 -0
- package/lib/adapter/use-cache-common.test.d.ts +1 -0
- package/lib/adapter/use-cache-common.test.js +646 -0
- package/lib/adapter/use-cache-default-handler.d.ts +24 -0
- package/lib/adapter/use-cache-default-handler.js +90 -0
- package/lib/adapter/use-cache-default-handler.mjs +38645 -0
- package/lib/adapter/use-cache-handlers.test.d.ts +1 -0
- package/lib/adapter/use-cache-handlers.test.js +349 -0
- package/lib/adapter/use-cache-remote-handler.d.ts +26 -0
- package/lib/adapter/use-cache-remote-handler.js +186 -0
- package/lib/{image-optimization/handler.mjs → adapter/use-cache-remote-handler.mjs} +33572 -38798
- package/lib/generated-structs/OptionalNextjsApiProps.d.ts +59 -0
- package/lib/generated-structs/OptionalNextjsApiProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsCacheProps.d.ts +15 -6
- package/lib/generated-structs/OptionalNextjsCacheProps.js +1 -1
- package/lib/generated-structs/OptionalNextjsContainersProps.d.ts +25 -11
- package/lib/generated-structs/OptionalNextjsContainersProps.js +1 -1
- package/lib/generated-structs/OptionalNextjsDistributionProps.d.ts +31 -9
- package/lib/generated-structs/OptionalNextjsDistributionProps.js +1 -1
- package/lib/generated-structs/OptionalNextjsPostDeployProps.d.ts +8 -0
- package/lib/generated-structs/OptionalNextjsPostDeployProps.js +1 -1
- package/lib/generated-structs/OptionalPostDeployCustomResourceProperties.d.ts +6 -4
- package/lib/generated-structs/OptionalPostDeployCustomResourceProperties.js +1 -1
- package/lib/index.d.ts +6 -7
- package/lib/index.js +2 -4
- package/lib/lambdas/post-deploy/prune-cache-bucket.d.ts +7 -3
- package/lib/lambdas/post-deploy/prune-cache-bucket.js +57 -71
- package/lib/lambdas/post-deploy/prune-cache-bucket.test.d.ts +1 -0
- package/lib/lambdas/post-deploy/prune-cache-bucket.test.js +114 -0
- package/lib/lambdas/post-deploy/prune-revalidation-table.d.ts +1 -0
- package/lib/lambdas/post-deploy/prune-revalidation-table.js +23 -31
- package/lib/lambdas/post-deploy/prune-revalidation-table.test.d.ts +1 -0
- package/lib/lambdas/post-deploy/prune-revalidation-table.test.js +71 -0
- package/lib/lambdas/post-deploy/prune-s3.d.ts +14 -5
- package/lib/lambdas/post-deploy/prune-s3.js +41 -12
- package/lib/lambdas/post-deploy/prune-s3.test.js +97 -18
- package/lib/lambdas/redeploy-stage/redeploy-stage-function.d.ts +13 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage-function.js +55 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage.d.ts +24 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage.js +68 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage.lambda.d.ts +20 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage.lambda.js +24 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage.test.d.ts +1 -0
- package/lib/lambdas/redeploy-stage/redeploy-stage.test.js +93 -0
- package/lib/nextjs-api.d.ts +102 -18
- package/lib/nextjs-api.js +338 -38
- package/lib/nextjs-api.test.js +537 -1
- package/lib/nextjs-build/global-containers.Dockerfile +15 -10
- package/lib/nextjs-build/nextjs-build.d.ts +339 -63
- package/lib/nextjs-build/nextjs-build.js +684 -327
- package/lib/nextjs-build/nextjs-build.test.d.ts +1 -0
- package/lib/nextjs-build/nextjs-build.test.js +412 -0
- package/lib/nextjs-build/patch-fetch.js +1 -1
- package/lib/nextjs-build/patch-fetch.test.js +166 -11
- package/lib/nextjs-build/regional-containers.Dockerfile +17 -10
- package/lib/nextjs-cache.d.ts +82 -4
- package/lib/nextjs-cache.js +186 -10
- package/lib/nextjs-cache.test.js +176 -1
- package/lib/nextjs-compute/nextjs-compute-base-props.d.ts +21 -8
- package/lib/nextjs-compute/nextjs-compute-base-props.js +41 -1
- package/lib/nextjs-compute/nextjs-compute-base-props.test.d.ts +1 -0
- package/lib/nextjs-compute/nextjs-compute-base-props.test.js +44 -0
- package/lib/nextjs-compute/nextjs-containers.d.ts +19 -0
- package/lib/nextjs-compute/nextjs-containers.js +57 -20
- package/lib/nextjs-compute/nextjs-functions.d.ts +122 -7
- package/lib/nextjs-compute/nextjs-functions.js +113 -67
- package/lib/nextjs-compute/nextjs-functions.test.d.ts +1 -0
- package/lib/nextjs-compute/nextjs-functions.test.js +99 -0
- package/lib/nextjs-distribution.d.ts +194 -23
- package/lib/nextjs-distribution.js +535 -62
- package/lib/nextjs-distribution.test.d.ts +1 -0
- package/lib/nextjs-distribution.test.js +697 -0
- package/lib/nextjs-post-deploy.d.ts +13 -5
- package/lib/nextjs-post-deploy.js +13 -10
- package/lib/nextjs-post-deploy.test.d.ts +1 -0
- package/lib/nextjs-post-deploy.test.js +34 -0
- package/lib/nextjs-static-assets.d.ts +17 -4
- package/lib/nextjs-static-assets.js +22 -5
- package/lib/root-constructs/nextjs-base-construct.d.ts +102 -58
- package/lib/root-constructs/nextjs-base-construct.js +139 -47
- package/lib/root-constructs/nextjs-global-containers.d.ts +18 -20
- package/lib/root-constructs/nextjs-global-containers.js +20 -71
- package/lib/root-constructs/nextjs-global-functions.d.ts +26 -28
- package/lib/root-constructs/nextjs-global-functions.js +52 -70
- package/lib/root-constructs/nextjs-regional-containers.d.ts +18 -5
- package/lib/root-constructs/nextjs-regional-containers.js +8 -15
- package/lib/root-constructs/nextjs-regional-functions.d.ts +22 -18
- package/lib/root-constructs/nextjs-regional-functions.js +8 -26
- package/lib/runtime/api-gateway-path.d.ts +34 -0
- package/lib/runtime/api-gateway-path.js +71 -0
- package/lib/runtime/api-gateway-path.test.d.ts +1 -0
- package/lib/runtime/api-gateway-path.test.js +65 -0
- package/lib/runtime/case-redirect.d.ts +22 -0
- package/lib/runtime/case-redirect.js +63 -0
- package/lib/runtime/case-redirect.test.d.ts +1 -0
- package/lib/runtime/case-redirect.test.js +32 -0
- package/lib/runtime/core.d.ts +234 -0
- package/lib/runtime/core.js +1213 -0
- package/lib/runtime/core.test.d.ts +1 -0
- package/lib/runtime/core.test.js +1678 -0
- package/lib/runtime/deployment-root.d.ts +13 -0
- package/lib/runtime/deployment-root.js +29 -0
- package/lib/runtime/dispatch.d.ts +331 -0
- package/lib/runtime/dispatch.js +751 -0
- package/lib/runtime/dispatch.test.d.ts +1 -0
- package/lib/runtime/dispatch.test.js +853 -0
- package/lib/runtime/entrypoints.d.ts +57 -0
- package/lib/runtime/entrypoints.js +115 -0
- package/lib/runtime/http/abort-signal.d.ts +6 -0
- package/lib/runtime/http/abort-signal.js +19 -0
- package/lib/runtime/http/abort-signal.test.d.ts +1 -0
- package/lib/runtime/http/abort-signal.test.js +49 -0
- package/lib/runtime/http/node-server.d.ts +38 -0
- package/lib/runtime/http/node-server.js +99 -0
- package/lib/runtime/http/node-server.test.d.ts +1 -0
- package/lib/runtime/http/node-server.test.js +96 -0
- package/lib/runtime/http/node-sink.d.ts +16 -0
- package/lib/runtime/http/node-sink.js +48 -0
- package/lib/runtime/http/node-sink.test.d.ts +1 -0
- package/lib/runtime/http/node-sink.test.js +66 -0
- package/lib/runtime/http/request.d.ts +62 -0
- package/lib/runtime/http/request.js +134 -0
- package/lib/runtime/http/request.test.d.ts +1 -0
- package/lib/runtime/http/request.test.js +103 -0
- package/lib/runtime/http/response.d.ts +77 -0
- package/lib/runtime/http/response.js +229 -0
- package/lib/runtime/http/response.test.d.ts +1 -0
- package/lib/runtime/http/response.test.js +178 -0
- package/lib/runtime/http/sink.d.ts +73 -0
- package/lib/runtime/http/sink.js +188 -0
- package/lib/runtime/http/sink.test.d.ts +1 -0
- package/lib/runtime/http/sink.test.js +257 -0
- package/lib/runtime/image-utils.d.ts +78 -0
- package/lib/runtime/image-utils.js +129 -0
- package/lib/runtime/image-utils.test.d.ts +1 -0
- package/lib/runtime/image-utils.test.js +237 -0
- package/lib/runtime/image.d.ts +76 -0
- package/lib/runtime/image.js +296 -0
- package/lib/runtime/image.test.d.ts +1 -0
- package/lib/runtime/image.test.js +405 -0
- package/lib/runtime/lambda-event.d.ts +4 -0
- package/lib/runtime/lambda-event.js +113 -0
- package/lib/runtime/lambda-event.test.d.ts +1 -0
- package/lib/runtime/lambda-event.test.js +119 -0
- package/lib/runtime/lambda.mjs +41595 -0
- package/lib/runtime/load-module.d.ts +8 -0
- package/lib/runtime/load-module.js +35 -0
- package/lib/runtime/manifest.d.ts +215 -0
- package/lib/runtime/manifest.js +118 -0
- package/lib/runtime/middleware.d.ts +43 -0
- package/lib/runtime/middleware.js +113 -0
- package/lib/runtime/middleware.test.d.ts +1 -0
- package/lib/runtime/middleware.test.js +259 -0
- package/lib/runtime/next-modules.d.ts +55 -0
- package/lib/runtime/next-modules.js +124 -0
- package/lib/runtime/next-modules.test.d.ts +1 -0
- package/lib/runtime/next-modules.test.js +34 -0
- package/lib/runtime/public-files.d.ts +32 -0
- package/lib/runtime/public-files.js +117 -0
- package/lib/runtime/public-files.test.d.ts +1 -0
- package/lib/runtime/public-files.test.js +97 -0
- package/lib/runtime/server.mjs +41588 -0
- package/lib/runtime/static-files.d.ts +50 -0
- package/lib/runtime/static-files.js +266 -0
- package/lib/runtime/static-files.test.d.ts +1 -0
- package/lib/runtime/static-files.test.js +118 -0
- package/lib/runtime/util.d.ts +28 -0
- package/lib/runtime/util.js +79 -0
- package/lib/utils/base-path.d.ts +106 -13
- package/lib/utils/base-path.js +254 -41
- package/lib/utils/base-path.test.js +219 -51
- package/lib/utils/get-architecture.d.ts +7 -8
- package/lib/utils/get-architecture.js +12 -13
- package/lib/utils/zip-directory.d.ts +14 -0
- package/lib/utils/zip-directory.js +121 -0
- package/lib/utils/zip-directory.test.d.ts +1 -0
- package/lib/utils/zip-directory.test.js +99 -0
- package/package.json +22 -3
- package/scripts/capture-adapter-fixture.mjs +325 -0
- package/scripts/e2e-deploy.sh +398 -0
- package/scripts/e2e-harness/README.md +707 -0
- package/scripts/e2e-harness/app.js +370 -0
- package/scripts/e2e-harness/common.sh +249 -0
- package/scripts/e2e-harness/screen.mjs +302 -0
- package/scripts/e2e-harness/stage-proxy.mjs +145 -0
- package/scripts/e2e-harness/type-filters.mjs +47 -0
- package/scripts/e2e-logs.sh +75 -0
- package/scripts/e2e-offline.sh +91 -0
- package/scripts/e2e-sweep.sh +370 -0
- package/scripts/e2e-warm.sh +114 -0
- package/scripts/zero-config-build.mjs +418 -0
- package/docs/1k-concurrent-users-executions.png +0 -0
- package/docs/plans/adapter-runtime-release.md +0 -362
- package/docs/plans/phase-0-image-function-opt-in.md +0 -295
- package/lib/generated-structs/OptionalDockerImageFunctionProps.d.ts +0 -425
- package/lib/generated-structs/OptionalDockerImageFunctionProps.js +0 -3
- package/lib/image-optimization/handler-utils.d.ts +0 -34
- package/lib/image-optimization/handler-utils.js +0 -83
- package/lib/image-optimization/handler-utils.test.js +0 -178
- package/lib/nextjs-build/functions.Dockerfile +0 -31
- package/lib/nextjs-compute/nextjs-image-function.d.ts +0 -53
- package/lib/nextjs-compute/nextjs-image-function.js +0 -59
- package/lib/utils/experimental-flags.d.ts +0 -24
- package/lib/utils/experimental-flags.js +0 -30
- /package/lib/{image-optimization/handler-utils.test.d.ts → adapter/adapter.test.d.ts} +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import { RouteInOtherGroupError } from "./entrypoints";
|
|
4
|
+
import { ResponseSink } from "./http/sink";
|
|
5
|
+
import { AdapterManifest } from "./manifest";
|
|
6
|
+
/** One request, normalized by a shell. */
|
|
7
|
+
export interface RuntimeRequest {
|
|
8
|
+
readonly method: string;
|
|
9
|
+
/** Origin-form target exactly as received: path + query, never absolute. */
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly headers: IncomingHttpHeaders;
|
|
12
|
+
readonly body?: Readable | Buffer;
|
|
13
|
+
readonly remoteAddress?: string;
|
|
14
|
+
/** `false` behind a TLS-terminating ALB. Only affects the synthesized socket. */
|
|
15
|
+
readonly encrypted?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Aborted when the client disconnects. Wiring it to `res.destroy()` is what
|
|
18
|
+
* makes `request.signal.onabort` fire inside route handlers.
|
|
19
|
+
*/
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
/**
|
|
22
|
+
* Whether `x-forwarded-host` names the host the client asked for. Only the
|
|
23
|
+
* shell can know: it is `true` for a Function URL event whose SigV4 Lambda
|
|
24
|
+
* verified. That is any IAM-authorized invoker — in practice CloudFront's
|
|
25
|
+
* Origin Access Control, whose viewer-request function overwrites the header
|
|
26
|
+
* with the viewer's `Host` (CloudFront has to replace `Host` itself with the
|
|
27
|
+
* Function URL's domain), plus principals granted `lambda:InvokeFunctionUrl`,
|
|
28
|
+
* who could replace the function's code anyway. It is also what
|
|
29
|
+
* `proxyExternal` drops OAC's signature on. Everywhere else the header is
|
|
30
|
+
* whatever the client sent, and it is
|
|
31
|
+
* ignored, as `next start` ignores it without `experimental.trustHostHeader`.
|
|
32
|
+
*/
|
|
33
|
+
readonly trustForwardedHost?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Set by {@link NextjsRuntime.handleInternally} for the in-process requests it
|
|
36
|
+
* makes: called with the `RouteInOtherGroupError` the route threw, instead of
|
|
37
|
+
* logging the misrouted-request warning, which describes a CloudFront or API
|
|
38
|
+
* Gateway problem this is not.
|
|
39
|
+
*/
|
|
40
|
+
readonly onRouteInOtherGroup?: (error: RouteInOtherGroupError) => void;
|
|
41
|
+
}
|
|
42
|
+
export interface NextjsRuntimeOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Absolute path to the deployment root — the staged tree every manifest key
|
|
45
|
+
* resolves against. `LAMBDA_TASK_ROOT` for Functions, the image `WORKDIR` for
|
|
46
|
+
* Containers; both shells derive it from their own location instead.
|
|
47
|
+
*/
|
|
48
|
+
readonly deploymentRoot: string;
|
|
49
|
+
readonly manifest: AdapterManifest;
|
|
50
|
+
/** `CDK_NEXTJS_STATIC_ASSETS_BUCKET_NAME`. */
|
|
51
|
+
readonly bucket?: string;
|
|
52
|
+
/** `CDK_NEXTJS_STATIC_ASSETS_KEY_PREFIX`. */
|
|
53
|
+
readonly bucketKeyPrefix?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare class NextjsRuntime {
|
|
56
|
+
private readonly options;
|
|
57
|
+
private readonly entrypoints;
|
|
58
|
+
private readonly dispatcher;
|
|
59
|
+
private readonly middleware?;
|
|
60
|
+
private readonly images;
|
|
61
|
+
/** The 500 ladder; see `statusTargets`. */
|
|
62
|
+
private readonly errorTargetFor;
|
|
63
|
+
/** The assets bucket, when `public/` files are served from it. */
|
|
64
|
+
private readonly publicBucket?;
|
|
65
|
+
constructor(options: NextjsRuntimeOptions);
|
|
66
|
+
get manifest(): AdapterManifest;
|
|
67
|
+
handle(request: RuntimeRequest, sink: ResponseSink): Promise<void>;
|
|
68
|
+
private route;
|
|
69
|
+
/**
|
|
70
|
+
* 404 or 500 when `pathname` is the prerendered `/404` or `/500` page — under
|
|
71
|
+
* `basePath` and, in an i18n app, any locale (`/fr/404`) — and `undefined`
|
|
72
|
+
* otherwise. `next start` matches the page, not the URL, so the locale does
|
|
73
|
+
* not matter.
|
|
74
|
+
*/
|
|
75
|
+
private statusPageStatus;
|
|
76
|
+
/**
|
|
77
|
+
* `next start`'s answer to a path nothing serves (`router-server.js`, the
|
|
78
|
+
* "404 case"), for both ways of getting here: dispatch matched nothing, or it
|
|
79
|
+
* matched a build asset that is not in the package.
|
|
80
|
+
*
|
|
81
|
+
* No-store, always. A prerendered `/_not-found` would otherwise send its
|
|
82
|
+
* cache entry's year-long `s-maxage`, and the CDN would keep the 404 past the
|
|
83
|
+
* deploy that adds the route. Set rather than forced: Next's page handlers
|
|
84
|
+
* only write a `Cache-Control` when none is set (`sendRenderResult`,
|
|
85
|
+
* `pages-handler.js`), which is exactly how `next start`'s own no-store here
|
|
86
|
+
* survives the render. `render404` is not this path: a `notFound()` from an
|
|
87
|
+
* ISR page is cacheable for that page's revalidate period.
|
|
88
|
+
*
|
|
89
|
+
* A missing `_next/static` file, and a GET or HEAD whose `Sec-Fetch-Dest`
|
|
90
|
+
* says it cannot display HTML (an `<img>`, a script, a font), get a
|
|
91
|
+
* plain-text `Not Found` instead of the rendered page — nothing would show
|
|
92
|
+
* it, and rendering it is the expensive part.
|
|
93
|
+
*
|
|
94
|
+
* Everything else renders the app's 404 as the path that was asked for, not
|
|
95
|
+
* as `/_not-found`: the App Router serializes the canonical URL into the RSC
|
|
96
|
+
* payload, so a client hydrated off a `/_not-found` payload reports the wrong
|
|
97
|
+
* `usePathname()` and pushes the wrong history entry. It renders with the
|
|
98
|
+
* request headers middleware set, too — a CSP nonce, say.
|
|
99
|
+
*/
|
|
100
|
+
private sendUnmatched;
|
|
101
|
+
/**
|
|
102
|
+
* One on-demand revalidation, run against this runtime rather than over the
|
|
103
|
+
* network. Wired in as `requestMeta.revalidate`; see the comment there.
|
|
104
|
+
*
|
|
105
|
+
* The response is thrown away — only its status matters — but it goes through
|
|
106
|
+
* the full {@link handle}, so the entrypoint sees a request with
|
|
107
|
+
* `x-prerender-revalidate` on it and writes the fresh entry through the cache
|
|
108
|
+
* handler exactly as a request from outside would. `handle` awaits its own
|
|
109
|
+
* `waitUntil` work, so the new entry is committed before `res.revalidate()`
|
|
110
|
+
* resolves, which is what callers that revalidate and then redirect depend on.
|
|
111
|
+
*
|
|
112
|
+
* The accept/throw rule is `NextServer#revalidate`'s, verbatim: a revalidation
|
|
113
|
+
* is successful if it was cached or answered 200, and `notFound: true`
|
|
114
|
+
* legitimately answers 404 for an `unstable_onlyGenerated` caller. Anything
|
|
115
|
+
* else throws, and `res.revalidate()` turns it into `Failed to revalidate
|
|
116
|
+
* <path>: <message>`.
|
|
117
|
+
*/
|
|
118
|
+
private revalidate;
|
|
119
|
+
/**
|
|
120
|
+
* An image optimization source that is not a file: `<Image src="/api/avatar">`
|
|
121
|
+
* served by a route handler. Wired in as the optimizer's `fetchInternal`, and
|
|
122
|
+
* run in process for the reasons {@link revalidate} is — `next start` fetches
|
|
123
|
+
* the source from itself over loopback, which here would be a second billed
|
|
124
|
+
* invocation through CloudFront.
|
|
125
|
+
*
|
|
126
|
+
* Only the authority is forwarded, as `next start`'s `fetchInternalImage`
|
|
127
|
+
* forwards none of the viewer's headers: the source is cached and served to
|
|
128
|
+
* everyone, so it must not depend on one viewer's cookies.
|
|
129
|
+
*/
|
|
130
|
+
private fetchInternal;
|
|
131
|
+
/**
|
|
132
|
+
* One request through {@link handle}, answered to this runtime instead of a
|
|
133
|
+
* client: the head, the body when it is wanted, and the error when the route
|
|
134
|
+
* is packaged into another `functionGroups` group. `handle` awaits the
|
|
135
|
+
* request's `waitUntil` work too, so whatever the render wrote is committed by
|
|
136
|
+
* the time this resolves.
|
|
137
|
+
*
|
|
138
|
+
* The body is kept only when `maximumBody` is set. One past it fails the
|
|
139
|
+
* response stream, which stops the route writing, and comes back as
|
|
140
|
+
* `tooLarge` rather than held in memory.
|
|
141
|
+
*/
|
|
142
|
+
private handleInternally;
|
|
143
|
+
/**
|
|
144
|
+
* App Router builds an invocable `/_not-found`, Pages Router a prerendered
|
|
145
|
+
* `404.html` (per locale under i18n) or else `/_error`; see `statusTargets`.
|
|
146
|
+
*/
|
|
147
|
+
private sendNotFound;
|
|
148
|
+
/**
|
|
149
|
+
* Turn a thrown error into a response, rendering the app's error page when it
|
|
150
|
+
* has one.
|
|
151
|
+
*
|
|
152
|
+
* Next.js's own page handlers catch, report and then *rethrow* ("rethrow so
|
|
153
|
+
* that we can handle serving error page", `pages-handler.ts`), which makes the
|
|
154
|
+
* error page the host's job — the same division of labor as `render404`. Without
|
|
155
|
+
* this ladder every throw answered a bare `text/plain` 500 and a custom
|
|
156
|
+
* `pages/_error` was dead code (`test/e2e/async-modules`, whose `/make-error`
|
|
157
|
+
* throws in `getServerSideProps`).
|
|
158
|
+
*
|
|
159
|
+
* Once the head is out there is nothing to say — destroying the stream is what
|
|
160
|
+
* tells the client the response is truncated rather than complete.
|
|
161
|
+
*/
|
|
162
|
+
private sendError;
|
|
163
|
+
/**
|
|
164
|
+
* A prerendered 404 or 500 page, or `false` when it cannot be read and the
|
|
165
|
+
* caller's plain-text fallback should answer. Read rather than `serveStatic`,
|
|
166
|
+
* which keeps the status already set but would answer a `Range` request with
|
|
167
|
+
* a 206 of the error page, and add `ETag`, `Last-Modified` and, where none is
|
|
168
|
+
* set yet, a public `Cache-Control` to it.
|
|
169
|
+
*/
|
|
170
|
+
private sendHtmlFile;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The request headers with {@link INTERNAL_HEADERS} removed, and `x-nextjs-data`
|
|
174
|
+
* put back for a `_next/data` request, which is what `next start`'s
|
|
175
|
+
* `resolveRoutes` does (`setIsNextDataRequest`) right after stripping it: the
|
|
176
|
+
* header is internal, but Next's handlers and middleware still read it — it is
|
|
177
|
+
* how a data request gets `x-nextjs-matched-path` — so a real data request has
|
|
178
|
+
* to keep it.
|
|
179
|
+
*/
|
|
180
|
+
export declare function withoutInternalHeaders(headers: IncomingHttpHeaders, target: string, basePath: string): IncomingHttpHeaders;
|
|
181
|
+
/**
|
|
182
|
+
* The `[route, dataRoute]` pairs a revalidated page is cached under at the edge.
|
|
183
|
+
*
|
|
184
|
+
* In an i18n app the Next client always puts the locale in a data href, the
|
|
185
|
+
* default locale included (`/_next/data/<id>/en/blog.json`, and `…/en.json` for
|
|
186
|
+
* the root), so the unprefixed data route names nothing CloudFront holds. The
|
|
187
|
+
* page is one locale's — `res.revalidate("/blog")` regenerates the default
|
|
188
|
+
* locale's, `"/fr/blog"` French — and the default locale's HTML is reachable,
|
|
189
|
+
* and cached, both with and without its prefix, so its two pairs share a data
|
|
190
|
+
* route, which the caller sends once.
|
|
191
|
+
*/
|
|
192
|
+
export declare function revalidatedPageRoutes(route: string, manifest: Pick<AdapterManifest, "buildId" | "config">): Array<[string, string]>;
|
|
193
|
+
/**
|
|
194
|
+
* Read the manifest and pin the layout it describes.
|
|
195
|
+
*
|
|
196
|
+
* `process.cwd()` is load-bearing and there is exactly one chance to get it
|
|
197
|
+
* right: Next.js inlines `relative(buildCwd, projectDir)` into every entrypoint
|
|
198
|
+
* and resolves it against the *runtime* cwd to find
|
|
199
|
+
* `required-server-files.json`, the prerender manifest, and the app's chunks.
|
|
200
|
+
* `assertBuildCwd` in `build-outputs.ts` keeps that inlined value `""`, so the
|
|
201
|
+
* whole invariant reduces to "cwd is the staged project dir" — asserted rather
|
|
202
|
+
* than assumed, because getting it wrong produces a
|
|
203
|
+
* `Cannot find module …/required-server-files.json` from inside compiled Next.js
|
|
204
|
+
* code with no indication that the layout is the problem.
|
|
205
|
+
*/
|
|
206
|
+
export declare function loadRuntime(deploymentRoot: string): Promise<NextjsRuntime>;
|
|
207
|
+
export interface SplitBody {
|
|
208
|
+
/** What `req` reads: the entrypoint's copy. */
|
|
209
|
+
readonly forRequest?: Readable | Buffer;
|
|
210
|
+
/** What `resolveRoutes` hands middleware. */
|
|
211
|
+
readonly forDispatch: ReadableStream;
|
|
212
|
+
/**
|
|
213
|
+
* Called once dispatch has returned, with whether middleware answered the
|
|
214
|
+
* request itself. Lets go of whichever copy nothing will read any more.
|
|
215
|
+
*/
|
|
216
|
+
releaseUnread(middlewareResponded: boolean): void;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* `resolveRoutes` hands `requestBody` to middleware, which consumes it, while the
|
|
220
|
+
* entrypoint needs the same bytes — the same problem `next-server` solves with
|
|
221
|
+
* `getCloneableBody()`. Only split when there is middleware to feed: teeing costs
|
|
222
|
+
* a buffer copy of every upload on a path that would otherwise be a straight pipe.
|
|
223
|
+
*
|
|
224
|
+
* A `tee()` buffers, for the branch that is behind, every chunk the other one
|
|
225
|
+
* has read — so a branch that is never read holds the whole body. Middleware
|
|
226
|
+
* that doesn't read the body is the common case (and its matcher may not even
|
|
227
|
+
* have run it), after which the entrypoint streaming an upload would pile all
|
|
228
|
+
* of it up in the middleware branch: the whole upload in memory, on a
|
|
229
|
+
* container that serves other requests. So once dispatch returns, the branch
|
|
230
|
+
* with no reader left is cancelled — the middleware one, or the entrypoint one
|
|
231
|
+
* when middleware answered and `req` will never be read. Cancelling one
|
|
232
|
+
* branch leaves the source and the other branch running.
|
|
233
|
+
*/
|
|
234
|
+
export declare function splitBody(body: Readable | Buffer | undefined, hasMiddleware: boolean): SplitBody;
|