Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 6f1ce93

Browse files
committed
Merge branch 'master' into feature/incremental-static-regeneration
2 parents 0ee2f55 + c86bd09 commit 6f1ce93

File tree

13 files changed

+113
-13
lines changed

13 files changed

+113
-13
lines changed

packages/e2e-tests/next-app-with-locales/cypress/integration/pages.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ describe("Pages Tests", () => {
147147
cy.visit(path);
148148
cy.location("pathname").should("eq", path);
149149
cy.contains(`Hello ${path.slice(-1)}`);
150+
cy.request({ url: path }).then((response) => {
151+
// Next.js asPath does not include locale prefixes or basepath
152+
expect(response.body).to.contain(
153+
`|/fallback-blocking/${path.slice(-1)}|`
154+
);
155+
});
150156
});
151157
});
152158
});

packages/e2e-tests/next-app-with-locales/pages/fallback-blocking/[slug].tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import { GetStaticProps } from "next";
3+
import { useRouter } from "next/router";
34

45
type DynamicIndexPageProps = {
56
slug: string;
@@ -8,11 +9,13 @@ type DynamicIndexPageProps = {
89
export default function DynamicIndexPage(
910
props: DynamicIndexPageProps
1011
): JSX.Element {
12+
const router = useRouter();
1113
return (
1214
<React.Fragment>
1315
<div>
1416
{`Hello ${props.slug}. This is a dynamic SSG page using getStaticProps() with fallback blocking.`}
1517
</div>
18+
<div>{`|${router.asPath}|`}</div>
1619
</React.Fragment>
1720
);
1821
}

packages/libs/lambda-at-edge/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [1.8.0-alpha.39](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-28)
7+
8+
### Bug Fixes
9+
10+
- **lambda-at-edge:** fix router path in fallback SSG ([#1026](https://github.com/serverless-nextjs/serverless-next.js/issues/1026)) ([9772397](https://github.com/serverless-nextjs/serverless-next.js/commit/9772397fb15c2cf87ee45797aa52c92cd6b6c485))
11+
612
# [1.8.0-alpha.38](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-26)
713

814
**Note:** Version bump only for package @sls-next/lambda-at-edge

packages/libs/lambda-at-edge/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "1.8.0-alpha.38",
6+
"version": "1.8.0-alpha.39",
77
"description": "Provides handlers that can be used in CloudFront Lambda@Edge to deploy next.js applications to the edge",
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",

packages/libs/lambda-at-edge/src/default-handler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,13 @@ const handleOriginResponse = async ({
724724
) {
725725
// eslint-disable-next-line
726726
const page = require(`./${pagePath}`);
727+
// Reconstruct original uri for next/router
728+
if (uri.endsWith(".html")) {
729+
request.uri = uri.slice(0, uri.length - 5);
730+
if (manifest.trailingSlash) {
731+
request.uri += "/";
732+
}
733+
}
727734
const { req, res, responsePromise } = lambdaAtEdgeCompat(
728735
event.Records[0].cf,
729736
{

packages/serverless-components/nextjs-cdk-construct/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [1.19.0-alpha.47](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-28)
7+
8+
### Bug Fixes
9+
10+
- **nextjs-cdk-construct:** use posix paths for s3 assets and invalidations ([#1025](https://github.com/serverless-nextjs/serverless-next.js/issues/1025)) ([b8b4393](https://github.com/serverless-nextjs/serverless-next.js/commit/b8b439348ffd4f8e526645801df101f715e53797))
11+
12+
# [1.19.0-alpha.46](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-27)
13+
14+
### Features
15+
16+
- **sls-next/cdk-construct:** edgeLambdas concatenated with default edge lambdas ([#1024](https://github.com/serverless-nextjs/serverless-next.js/issues/1024)) ([32772c0](https://github.com/serverless-nextjs/serverless-next.js/commit/32772c00f03147b4dbeb3602dc947a488476fc4f))
17+
618
# [1.19.0-alpha.45](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-26)
719

820
**Note:** Version bump only for package @sls-next/cdk-construct

packages/serverless-components/nextjs-cdk-construct/__tests__/construct.test.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { SynthUtils } from "@aws-cdk/assert";
33
import { Stack } from "@aws-cdk/core";
44
import path from "path";
55
import { NextJSLambdaEdge } from "../src";
6-
import { Runtime } from "@aws-cdk/aws-lambda";
6+
import { Runtime, Function, Code } from "@aws-cdk/aws-lambda";
77
import { Certificate } from "@aws-cdk/aws-certificatemanager";
88
import { HostedZone } from "@aws-cdk/aws-route53";
9+
import { LambdaEdgeEventType } from "@aws-cdk/aws-cloudfront";
910

1011
describe("CDK Construct", () => {
1112
it("passes correct lambda options to underlying lambdas when single value passed", () => {
@@ -182,4 +183,56 @@ describe("CDK Construct", () => {
182183
const synthesizedStack = SynthUtils.toCloudFormation(stack);
183184
expect(synthesizedStack).toCountResources("AWS::Route53::RecordSet", 0);
184185
});
186+
187+
it("concatenates edgeLambdas passed to defaultBehavior", () => {
188+
const stack = new Stack();
189+
190+
const viewerRequestFunction = new Function(
191+
stack,
192+
"ViewerRequestEdgeFunction",
193+
{
194+
code: Code.fromInline(`module.handler = () => {}`),
195+
handler: "index.handler",
196+
runtime: Runtime.NODEJS_10_X,
197+
functionName: "viewerRequest-test"
198+
}
199+
);
200+
201+
new NextJSLambdaEdge(stack, "Stack", {
202+
serverlessBuildOutDir: path.join(__dirname, "fixtures/next-boilerplate"),
203+
runtime: Runtime.NODEJS_10_X,
204+
defaultBehavior: {
205+
edgeLambdas: [
206+
{
207+
functionVersion: viewerRequestFunction.currentVersion,
208+
eventType: LambdaEdgeEventType.VIEWER_REQUEST
209+
}
210+
]
211+
}
212+
});
213+
214+
const synthesizedStack = SynthUtils.toCloudFormation(stack);
215+
216+
expect(synthesizedStack).toHaveResourceLike(
217+
"AWS::CloudFront::Distribution",
218+
{
219+
DistributionConfig: {
220+
DefaultCacheBehavior: {
221+
LambdaFunctionAssociations: [
222+
{
223+
IncludeBody: true,
224+
EventType: LambdaEdgeEventType.ORIGIN_REQUEST.toString()
225+
},
226+
{
227+
EventType: LambdaEdgeEventType.ORIGIN_RESPONSE.toString()
228+
},
229+
{
230+
EventType: LambdaEdgeEventType.VIEWER_REQUEST.toString()
231+
}
232+
]
233+
}
234+
}
235+
}
236+
);
237+
});
185238
});

packages/serverless-components/nextjs-cdk-construct/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"access": "public"
55
},
66
"description": "Serverless Next.js powered by AWS CDK",
7-
"version": "1.19.0-alpha.45",
7+
"version": "1.19.0-alpha.47",
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",
1010
"author": "Henry Kirkness <[email protected]>",

packages/serverless-components/nextjs-cdk-construct/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
253253
}
254254
);
255255

256-
const edgeLambdas = [
256+
const edgeLambdas: cloudfront.EdgeLambda[] = [
257257
{
258258
includeBody: true,
259259
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
@@ -265,6 +265,13 @@ export class NextJSLambdaEdge extends cdk.Construct {
265265
}
266266
];
267267

268+
const { edgeLambdas: additionalDefaultEdgeLambdas, ...defaultBehavior } =
269+
props.defaultBehavior || {};
270+
271+
if (additionalDefaultEdgeLambdas) {
272+
edgeLambdas.push(...additionalDefaultEdgeLambdas);
273+
}
274+
268275
this.distribution = new cloudfront.Distribution(
269276
this,
270277
"NextJSDistribution",
@@ -282,7 +289,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
282289
compress: true,
283290
cachePolicy: this.nextLambdaCachePolicy,
284291
edgeLambdas,
285-
...(props.defaultBehavior || {})
292+
...(defaultBehavior || {})
286293
},
287294
additionalBehaviors: {
288295
...(this.nextImageLambda
@@ -400,7 +407,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
400407
// The source contents will be unzipped to and loaded into the S3 bucket
401408
// at the root '/', we don't want this, we want to maintain the same
402409
// path on S3 as their local path.
403-
destinationKeyPrefix: path.relative(assetsDirectory, assetPath),
410+
destinationKeyPrefix: path.posix.relative(assetsDirectory, assetPath),
404411

405412
// Source directories are uploaded with `--sync` this means that any
406413
// files that don't exist in the source directory, but do in the S3

packages/serverless-components/nextjs-cdk-construct/src/utils/readAssetsDirectory.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ const readAssetsDirectory = (options: {
3333
assetsDirectory: string;
3434
}): CacheConfig => {
3535
const { assetsDirectory } = options;
36-
const publicFiles = path.join(assetsDirectory, "public");
37-
const staticFiles = path.join(assetsDirectory, "static");
38-
const staticPages = path.join(assetsDirectory, "static-pages");
39-
const nextData = path.join(assetsDirectory, "_next", "data");
40-
const nextStatic = path.join(assetsDirectory, "_next", "static");
36+
// Ensure these are posix paths so they are compatible with AWS S3
37+
const publicFiles = path.posix.join(assetsDirectory, "public");
38+
const staticFiles = path.posix.join(assetsDirectory, "static");
39+
const staticPages = path.posix.join(assetsDirectory, "static-pages");
40+
const nextData = path.posix.join(assetsDirectory, "_next", "data");
41+
const nextStatic = path.posix.join(assetsDirectory, "_next", "static");
4142

4243
return filterNonExistentPathKeys({
4344
publicFiles: {

packages/serverless-components/nextjs-cdk-construct/src/utils/readInvalidationPathsFromManifest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { OriginRequestDefaultHandlerManifest } from "@sls-next/lambda-at-edge";
33

44
const dynamicPathToInvalidationPath = (dynamicPath: string) => {
55
const [firstSegment] = dynamicPath.split("/:");
6-
return path.join(firstSegment || "/", "*");
6+
// Ensure this is posix path as CloudFront needs forward slash in invalidation
7+
return path.posix.join(firstSegment || "/", "*");
78
};
89

910
export const readInvalidationPathsFromManifest = (

packages/serverless-components/nextjs-component/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [1.19.0-alpha.51](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-28)
7+
8+
**Note:** Version bump only for package @sls-next/serverless-component
9+
610
# [1.19.0-alpha.50](https://github.com/serverless-nextjs/serverless-next.js/compare/@sls-next/[email protected]...@sls-next/[email protected]) (2021-04-26)
711

812
**Note:** Version bump only for package @sls-next/serverless-component

packages/serverless-components/nextjs-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "1.19.0-alpha.50",
6+
"version": "1.19.0-alpha.51",
77
"description": "Serverless Next.js powered by Serverless Components",
88
"main": "./serverless.js",
99
"types": "dist/component.d.ts",

0 commit comments

Comments
 (0)