Skip to content

Commit

Permalink
Merge branch 'sst:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisobadia authored Nov 27, 2023
2 parents bdb7e98 + 8bc075b commit bb09162
Show file tree
Hide file tree
Showing 22 changed files with 2,160 additions and 430 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ next-env.d.ts

.turbo
# Tests
tests-unit/coverage
packages/tests-unit/coverage
test-results

.sst/
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ OpenNext aims to support all Next.js 13 features. Some features are work in prog

## Who is using OpenNext?

[NHS England](https://github.com/nhs-england-tools/terraform-aws-opennext),
[Udacity](https://engineering.udacity.com/deploying-next-js-on-the-edge-with-sst-is-sst-the-game-changer-its-claimed-to-be-1f05a0abc27c)
[Gymshark UK](https://uk.gymshark.com), [Udacity](https://engineering.udacity.com/deploying-next-js-on-the-edge-with-sst-is-sst-the-game-changer-its-claimed-to-be-1f05a0abc27c), [TUDN](https://www.tudn.com), [NHS England](https://github.com/nhs-england-tools/terraform-aws-opennext)



## Example
Expand All @@ -54,6 +54,8 @@ Vercel link: https://open-next.vercel.app

### Environment variables

- AWS_SDK_DYNAMODB_MAX_ATTEMPTS: The maximum number of times requests that encounter retryable failures should be attempted for DynamoDB. Defaults to 3.
- AWS_SDK_S3_MAX_ATTEMPTS: The maximum number of times requests that encounter retryable failures should be attempted for S3. Defaults to 3.
- DYNAMO_BATCH_WRITE_COMMAND_CONCURRENCY: The number of concurrent batch write commands to DynamoDB. Defaults to 4 in an effort to leave plenty of DynamoDB write request capacity for the production load.

## Contribute
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/advanced/workaround.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### WORKAROUND: Create one cache behavior per top-level file and folder in `public/` (AWS specific)

As mentioned in the [Asset files](#asset-files) section, files in your app's `public/` folder are static and are uploaded to the S3 bucket. And requests for these files are handled by the S3 bucket, like so:
As mentioned in the [Asset files](./architecture#asset-files) section, files in your app's `public/` folder are static and are uploaded to the S3 bucket. And requests for these files are handled by the S3 bucket, like so:

```
https://my-nextjs-app.com/favicon.ico
Expand Down Expand Up @@ -111,7 +111,7 @@ export function middleware(request: NextRequest) {

#### WORKAROUND: `NextServer` does not set cache headers for HTML pages

As mentioned in the [Server function](#server-lambda-function) section, the server function uses the `NextServer` class from Next.js' build output to handle requests. However, `NextServer` does not seem to set the correct `Cache Control` headers.
As mentioned in the [Server function](./architecture#server-lambda-function) section, the server function uses the `NextServer` class from Next.js' build output to handle requests. However, `NextServer` does not seem to set the correct `Cache Control` headers.

To work around the issue, the server function checks if the request is for an HTML page, and sets the `Cache Control` header to:

Expand Down Expand Up @@ -154,7 +154,7 @@ You can build the file path like this:
path.join(process.cwd(), "posts", "my-post.md");
```

As mentioned in the [Server function](#server-lambda-function) section, in a non-monorepo setup, the `server-function` bundle looks like:
As mentioned in the [Server function](./architecture#server-lambda-function) section, in a non-monorepo setup, the `server-function` bundle looks like:

```
.next/
Expand Down Expand Up @@ -201,4 +201,4 @@ Nextjs 13.4.13 refactored the middleware logic so that it no longer runs in the
We've introduced a custom esbuild plugin to conditionally inject and override code to properly handle the breaking changes.

The default request handler is in `adapters/plugins/default.ts`
When open-next needs to override that implementation due to NextJs breaking compatibility, the `createServerBundle` in `build.ts` determines the proper overrides to replace the code of the `default.ts` file.
When open-next needs to override that implementation due to NextJs breaking compatibility, the `createServerBundle` in `build.ts` determines the proper overrides to replace the code of the `default.ts` file.
15 changes: 7 additions & 8 deletions docs/pages/inner_workings/isr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ They can also be called on fetch requests if the `cache` option is not set to `n

There is also some cost associated to deployment since you need to upload the cache to S3 and upload the tags to DynamoDB.

For the examples here, let's assume an app route with a 5 minute revalidation delay in us-east-1 (App uses 3 instead of 2 `GetObject`). This is assuming you get constant traffic to the route (If you get no traffic, you will only pay for the storage cost).
For the examples here, let's assume an app route with a 5 minute revalidation delay in us-east-1. This is assuming you get constant traffic to the route (If you get no traffic, you will only pay for the storage cost).

##### S3
- Each `get` request to the cache will result in at least 1 `ListRequest` in S3 and between 2 and 3 `GetObject`
- Each `get` request to the cache will result in at least 1 `GetObject`

```
List Request cost - 8,640 requests * $0.005 per 1,000 requests = $0.0432
GetObject cost - 8,640 requests * $0.0004 per 1,000 requests * 3 = $0.010368
Total cost - $0.053568 per route per month
GetObject cost - 8,640 requests * $0.0004 per 1,000 requests = $0.003456
Total cost - $0.003456 per route per month
```

- Each `set` request to the cache will result in 2 to 3 `PutObject` in S3
- Each `set` request to the cache will result in 1 `PutObject` in S3

```
PutObject cost - 8,640 requests * $0.005 per 1,000 requests * 3 = $0.1296
Total cost - $0.1296 per route per month
PutObject cost - 8,640 requests * $0.005 per 1,000 requests = $0.0432
Total cost - $0.0432 per route per month
```

You can then calculate the cost based on your usage and the [S3 pricing](https://aws.amazon.com/s3/pricing/)
Expand Down
11 changes: 4 additions & 7 deletions examples/sst/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
"version": "0.0.0",
"type": "module",
"private": true,
"scripts": {
},
"dependencies": {

},
"scripts": {},
"dependencies": {},
"devDependencies": {
"aws-cdk-lib": "2.91.0",
"aws-cdk-lib": "2.101.1",
"constructs": "10.2.69",
"sst": "2.24.24"
"sst": "2.35.1"
}
}
5 changes: 4 additions & 1 deletion examples/sst/stacks/AppRouter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextjsSite } from "./NextjsSite";
import { NextjsSite } from "sst/constructs";

export function AppRouter({ stack }) {
const site = new NextjsSite(stack, "approuter", {
Expand All @@ -7,6 +7,9 @@ export function AppRouter({ stack }) {
bind: [],
environment: {},
timeout: "20 seconds",
experimental: {
streaming: true,
},
});

stack.addOutputs({
Expand Down
7 changes: 0 additions & 7 deletions examples/sst/stacks/NextjsSite.ts

This file was deleted.

34 changes: 34 additions & 0 deletions packages/open-next/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# open-next

## 2.3.2

### Patch Changes

- 4be2ac8: Reduce AWS S3 warning logs; add maxAttempts config to AWS SDK call

## 2.3.1

### Patch Changes

- 95bf402: Display sharp installation log on failure
- 1ed5ffd: Print plugin info in debug mode
- 1d83dab: Handle .map files during bundling cache assets

## 2.3.0

### Minor Changes

- 22e3e47: Fix inconsistencies with swr and isr (#289)

Exclude manifest.json, robots.txt and sitemap.xml from routing matcher (#287)

Feature/rewrite with query string (#281)

Double chunk DDB batch writes to not overwhelm DDB on load (#293)

fix: copy favicon.ico from app dir (#301)

fix: XML Malformed Error DeleteObjectsCommand (#300)

Fix external rewrite (#299)

Perf Reduce s3 calls (#295)

## 2.2.4

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/open-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"access": "public"
},
"name": "open-next",
"version": "2.2.4",
"version": "2.3.2",
"bin": {
"open-next": "./dist/index.js"
},
Expand Down Expand Up @@ -52,10 +52,10 @@
"typescript": "^4.9.3"
},
"bugs": {
"url": "https://github.com/serverless-stack/open-next/issues"
"url": "https://github.com/sst/open-next/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/serverless-stack/open-next.git"
"url": "git+https://github.com/sst/open-next.git"
}
}
Loading

0 comments on commit bb09162

Please sign in to comment.