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

Commit

Permalink
Merge branch 'master' into feature/incremental-static-regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkness committed Apr 29, 2021
2 parents 0ee2f55 + c86bd09 commit 6f1ce93
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ describe("Pages Tests", () => {
cy.visit(path);
cy.location("pathname").should("eq", path);
cy.contains(`Hello ${path.slice(-1)}`);
cy.request({ url: path }).then((response) => {
// Next.js asPath does not include locale prefixes or basepath
expect(response.body).to.contain(
`|/fallback-blocking/${path.slice(-1)}|`
);
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { GetStaticProps } from "next";
import { useRouter } from "next/router";

type DynamicIndexPageProps = {
slug: string;
Expand All @@ -8,11 +9,13 @@ type DynamicIndexPageProps = {
export default function DynamicIndexPage(
props: DynamicIndexPageProps
): JSX.Element {
const router = useRouter();
return (
<React.Fragment>
<div>
{`Hello ${props.slug}. This is a dynamic SSG page using getStaticProps() with fallback blocking.`}
</div>
<div>{`|${router.asPath}|`}</div>
</React.Fragment>
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/libs/lambda-at-edge/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [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)

### Bug Fixes

- **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))

# [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)

**Note:** Version bump only for package @sls-next/lambda-at-edge
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/lambda-at-edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.8.0-alpha.38",
"version": "1.8.0-alpha.39",
"description": "Provides handlers that can be used in CloudFront Lambda@Edge to deploy next.js applications to the edge",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
7 changes: 7 additions & 0 deletions packages/libs/lambda-at-edge/src/default-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,13 @@ const handleOriginResponse = async ({
) {
// eslint-disable-next-line
const page = require(`./${pagePath}`);
// Reconstruct original uri for next/router
if (uri.endsWith(".html")) {
request.uri = uri.slice(0, uri.length - 5);
if (manifest.trailingSlash) {
request.uri += "/";
}
}
const { req, res, responsePromise } = lambdaAtEdgeCompat(
event.Records[0].cf,
{
Expand Down
12 changes: 12 additions & 0 deletions packages/serverless-components/nextjs-cdk-construct/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [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)

### Bug Fixes

- **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))

# [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)

### Features

- **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))

# [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)

**Note:** Version bump only for package @sls-next/cdk-construct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { SynthUtils } from "@aws-cdk/assert";
import { Stack } from "@aws-cdk/core";
import path from "path";
import { NextJSLambdaEdge } from "../src";
import { Runtime } from "@aws-cdk/aws-lambda";
import { Runtime, Function, Code } from "@aws-cdk/aws-lambda";
import { Certificate } from "@aws-cdk/aws-certificatemanager";
import { HostedZone } from "@aws-cdk/aws-route53";
import { LambdaEdgeEventType } from "@aws-cdk/aws-cloudfront";

describe("CDK Construct", () => {
it("passes correct lambda options to underlying lambdas when single value passed", () => {
Expand Down Expand Up @@ -182,4 +183,56 @@ describe("CDK Construct", () => {
const synthesizedStack = SynthUtils.toCloudFormation(stack);
expect(synthesizedStack).toCountResources("AWS::Route53::RecordSet", 0);
});

it("concatenates edgeLambdas passed to defaultBehavior", () => {
const stack = new Stack();

const viewerRequestFunction = new Function(
stack,
"ViewerRequestEdgeFunction",
{
code: Code.fromInline(`module.handler = () => {}`),
handler: "index.handler",
runtime: Runtime.NODEJS_10_X,
functionName: "viewerRequest-test"
}
);

new NextJSLambdaEdge(stack, "Stack", {
serverlessBuildOutDir: path.join(__dirname, "fixtures/next-boilerplate"),
runtime: Runtime.NODEJS_10_X,
defaultBehavior: {
edgeLambdas: [
{
functionVersion: viewerRequestFunction.currentVersion,
eventType: LambdaEdgeEventType.VIEWER_REQUEST
}
]
}
});

const synthesizedStack = SynthUtils.toCloudFormation(stack);

expect(synthesizedStack).toHaveResourceLike(
"AWS::CloudFront::Distribution",
{
DistributionConfig: {
DefaultCacheBehavior: {
LambdaFunctionAssociations: [
{
IncludeBody: true,
EventType: LambdaEdgeEventType.ORIGIN_REQUEST.toString()
},
{
EventType: LambdaEdgeEventType.ORIGIN_RESPONSE.toString()
},
{
EventType: LambdaEdgeEventType.VIEWER_REQUEST.toString()
}
]
}
}
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"access": "public"
},
"description": "Serverless Next.js powered by AWS CDK",
"version": "1.19.0-alpha.45",
"version": "1.19.0-alpha.47",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Henry Kirkness <[email protected]>",
Expand Down
13 changes: 10 additions & 3 deletions packages/serverless-components/nextjs-cdk-construct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
}
);

const edgeLambdas = [
const edgeLambdas: cloudfront.EdgeLambda[] = [
{
includeBody: true,
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
Expand All @@ -265,6 +265,13 @@ export class NextJSLambdaEdge extends cdk.Construct {
}
];

const { edgeLambdas: additionalDefaultEdgeLambdas, ...defaultBehavior } =
props.defaultBehavior || {};

if (additionalDefaultEdgeLambdas) {
edgeLambdas.push(...additionalDefaultEdgeLambdas);
}

this.distribution = new cloudfront.Distribution(
this,
"NextJSDistribution",
Expand All @@ -282,7 +289,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
compress: true,
cachePolicy: this.nextLambdaCachePolicy,
edgeLambdas,
...(props.defaultBehavior || {})
...(defaultBehavior || {})
},
additionalBehaviors: {
...(this.nextImageLambda
Expand Down Expand Up @@ -400,7 +407,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
// The source contents will be unzipped to and loaded into the S3 bucket
// at the root '/', we don't want this, we want to maintain the same
// path on S3 as their local path.
destinationKeyPrefix: path.relative(assetsDirectory, assetPath),
destinationKeyPrefix: path.posix.relative(assetsDirectory, assetPath),

// Source directories are uploaded with `--sync` this means that any
// files that don't exist in the source directory, but do in the S3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ const readAssetsDirectory = (options: {
assetsDirectory: string;
}): CacheConfig => {
const { assetsDirectory } = options;
const publicFiles = path.join(assetsDirectory, "public");
const staticFiles = path.join(assetsDirectory, "static");
const staticPages = path.join(assetsDirectory, "static-pages");
const nextData = path.join(assetsDirectory, "_next", "data");
const nextStatic = path.join(assetsDirectory, "_next", "static");
// Ensure these are posix paths so they are compatible with AWS S3
const publicFiles = path.posix.join(assetsDirectory, "public");
const staticFiles = path.posix.join(assetsDirectory, "static");
const staticPages = path.posix.join(assetsDirectory, "static-pages");
const nextData = path.posix.join(assetsDirectory, "_next", "data");
const nextStatic = path.posix.join(assetsDirectory, "_next", "static");

return filterNonExistentPathKeys({
publicFiles: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { OriginRequestDefaultHandlerManifest } from "@sls-next/lambda-at-edge";

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

export const readInvalidationPathsFromManifest = (
Expand Down
4 changes: 4 additions & 0 deletions packages/serverless-components/nextjs-component/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [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)

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

# [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)

**Note:** Version bump only for package @sls-next/serverless-component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.19.0-alpha.50",
"version": "1.19.0-alpha.51",
"description": "Serverless Next.js powered by Serverless Components",
"main": "./serverless.js",
"types": "dist/component.d.ts",
Expand Down

0 comments on commit 6f1ce93

Please sign in to comment.