Skip to content

Commit f469fcc

Browse files
sommeeeerkhuezy
andauthored
docs: fix links in index.mdx and refactor simple example page (#442)
* docs: fix links in index.mdx and refactor simple example page * Update docs/pages/config/simple_example.mdx Co-authored-by: khuezy <khuezy.nguyen@gmail.com> * docs: add aws4fetch instead of aws sdk to simple example * docs: add fix for streaming when body is empty * docs: remove callout in running in lambda@edge --------- Co-authored-by: khuezy <khuezy.nguyen@gmail.com>
1 parent 19b89c0 commit f469fcc

File tree

2 files changed

+97
-35
lines changed

2 files changed

+97
-35
lines changed

docs/pages/config/simple_example.mdx

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1+
import { Callout } from 'nextra/components';
2+
13
Here you can find the most common `open-next.config.ts` file examples that you could easily take as a starting point for your own configuration.
24

35
## Streaming with lambda
46

7+
<Callout type="warning" emoji="⚠️">
8+
AWS has a bunch of different implementations of streaming in production. You
9+
might be lucky and have a fully working one, but you might have one that are
10+
not suitable for production. Be aware that there is nothing to do to prevent
11+
AWS from breaking your deployment (same code and same runtime might break from
12+
one day to another) [Thread
13+
1](https://discord.com/channels/983865673656705025/1230482660913184800)
14+
[Thread
15+
2](https://discord.com/channels/983865673656705025/1249368592558985247) <br />{' '}
16+
<br /> On some AWS accounts the response can hang if the body is empty. There
17+
is a workaround for that on OpenNext 3.0.3+, setting environment variable
18+
`OPEN_NEXT_FORCE_NON_EMPTY_RESPONSE` to `"true"`. This will ensure that the
19+
stream body is not empty. <br /> <br />
20+
If you have an issue with streaming send a message on [discord](https://sst.dev/discord)
21+
and contact AWS support to let them know of the issue.
22+
</Callout>
23+
524
```ts
6-
import type { OpenNextConfig } from 'open-next/types/open-next'
25+
import type { OpenNextConfig } from 'open-next/types/open-next';
726
const config = {
8-
default: {
9-
override: {
10-
wrapper: "aws-lambda-streaming", // This is necessary to enable lambda streaming
27+
default: {
28+
override: {
29+
wrapper: 'aws-lambda-streaming', // This is necessary to enable lambda streaming
1130
},
1231
},
13-
} satisfies OpenNextConfig
32+
} satisfies OpenNextConfig;
1433

1534
export default config;
1635
```
1736

1837
## Splitting the server
1938

2039
```ts
21-
import type { OpenNextConfig } from 'open-next/types/open-next'
40+
import type { OpenNextConfig } from 'open-next/types/open-next';
2241
const config = {
2342
// This is the default server, similar to the server-function in open-next v2
2443
// In this case we are not providing any override, so it will generate a normal lambda (i.e. no streaming)
@@ -30,13 +49,55 @@ const config = {
3049
patterns: ['route1', 'route2', 'route3'],
3150
// For app dir, you need to include route|page, no need to include layout or loading
3251
// It needs to be prepended with app/ or pages/ depending on the directory used
33-
routes: ["app/route1/page", "app/route2/page", "pages/route3"],
52+
routes: ['app/route1/page', 'app/route2/page', 'pages/route3'],
3453
override: {
35-
wrapper: "aws-lambda-streaming",
36-
}
54+
wrapper: 'aws-lambda-streaming',
55+
},
3756
},
38-
}
39-
} satisfies OpenNextConfig
57+
},
58+
} satisfies OpenNextConfig;
59+
60+
export default config;
61+
```
62+
63+
## Use aws4fetch instead of AWS sdk
64+
65+
<Callout type="info" emoji="ℹ️">
66+
By default we use S3, DynamoDB and SQS for handling ISR/SSG and the fetch
67+
cache. We interact with them using AWS sdk v3. This can contribute a lot to
68+
the cold start. There is a built-in option to use
69+
[aws4fetch](https://github.com/mhart/aws4fetch) instead of the AWS sdk that
70+
can reduce cold start up to 300ms. Requires `OpenNext v3.0.3+`. Here is how
71+
you enable it:
72+
</Callout>
73+
74+
```ts
75+
import type { OpenNextConfig } from 'open-next/types/open-next';
76+
const config = {
77+
default: {
78+
override: {
79+
tagCache: 'dynamodb-lite',
80+
incrementalCache: 's3-lite',
81+
queue: 'sqs-lite',
82+
},
83+
},
84+
} satisfies OpenNextConfig;
85+
86+
export default config;
87+
```
88+
89+
## Running in Lambda@Edge
90+
91+
```ts
92+
import type { OpenNextConfig } from 'open-next/types/open-next';
93+
const config = {
94+
default: {
95+
placement: 'global',
96+
override: {
97+
converter: 'aws-cloudfront',
98+
},
99+
},
100+
} satisfies OpenNextConfig;
40101

41102
export default config;
42103
```
@@ -45,48 +106,48 @@ export default config;
45106

46107
This will generate 2 server functions, the default one and the edge one. The edge one will still be deployed as a lambda function, but it will be deployed in the edge runtime.
47108

48-
Edge runtime function have less cold start time, but you can only deploy one route per function. They also does not have the middleware bundled in the function, so you need to use external middleware if you need it in front of the edge function.
109+
Edge runtime function have less cold start time, but you can only deploy one route per function. They also do not have the middleware bundled in the function, so you need to use external middleware if you need it in front of the edge function.
49110

50111
```ts
51-
import type { OpenNextConfig } from 'open-next/types/open-next'
112+
import type { OpenNextConfig } from 'open-next/types/open-next';
52113
const config = {
53114
default: {},
54115
functions: {
55116
edge: {
56-
runtime: "edge",
117+
runtime: 'edge',
57118
//placement: "global", If you want your function to be deployed globally (i.e. lambda@edge) uncomment this line. Otherwise it will be deployed in the region specified in the stack
58-
routes: ["app/api/test/route"],
59-
patterns: ["api/test"],
119+
routes: ['app/api/test/route'],
120+
patterns: ['api/test'],
60121
},
61-
}
62-
} satisfies OpenNextConfig
122+
},
123+
} satisfies OpenNextConfig;
63124

64125
export default config;
65126
```
66127

67128
## External middleware
68129

69-
In some cases (edge runtime, function splitting with some middleware rewrites, etc) you might want to use external middleware.
70-
With the default middleware configuration, it is bundled for a deployment in lambda@edge.
130+
In some cases (edge runtime, function splitting with some middleware rewrites, etc) you might want to use external middleware.
131+
With the default middleware configuration, it is bundled for a deployment in lambda@edge.
71132
This is how you can do it:
72133

73134
```ts
74-
import type { OpenNextConfig } from 'open-next/types/open-next'
135+
import type { OpenNextConfig } from 'open-next/types/open-next';
75136
const config = {
76137
default: {},
77138
functions: {
78139
myFn: {
79140
patterns: ['route1', 'route2', 'route3'],
80-
routes: ["app/route1/page", "app/route2/page", "pages/route3"],
141+
routes: ['app/route1/page', 'app/route2/page', 'pages/route3'],
81142
override: {
82-
wrapper: "aws-lambda-streaming",
83-
}
143+
wrapper: 'aws-lambda-streaming',
144+
},
84145
},
85146
},
86147
middleware: {
87-
external: true
88-
}
89-
} satisfies OpenNextConfig
148+
external: true,
149+
},
150+
} satisfies OpenNextConfig;
90151

91152
export default config;
92-
```
153+
```

docs/pages/index.mdx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {SITE} from "../config"
2-
import { Callout } from 'nextra/components'
1+
import { SITE } from '../config';
2+
import { Callout } from 'nextra/components';
33

44
<Callout>
55
This docs is for the V3 of OpenNext. If you are looking for the V2 docs, you can find them [here](/v2).
66

77
If you're migrating from V2 to V3, you can find the migration guide [here](/migration#from-opennext-v2).
8+
89
</Callout>
910

1011
### Open source Next.js adapter
1112

1213
---
1314

14-
15-
OpenNext takes the Next.js build output and converts it into packages that can be deployed across a variety of environments.
15+
OpenNext takes the Next.js build output and converts it into packages that can be deployed across a variety of environments.
1616
Natively OpenNext has support for AWS Lambda and classic Node Server. It also offer partial support for the `edge` runtime in Cloudflare Workers.
1717

1818
One notable feature of OpenNext is its ability to split the Next.js output, enabling selective deployment to different targets such as AWS Lambda, Cloudflare Workers, or Amazon ECS. This facilitates a tailored deployment strategy that aligns with the specific needs of your application.
@@ -38,6 +38,7 @@ Closed source SaaS products like [Amplify](https://aws.amazon.com/amplify/) have
3838
---
3939

4040
We need your help keeping it up to date and feature complete. Make sure to [**join us on Discord**](https://sst.dev/discord) and [**star us on GitHub**](https://github.com/sst/open-next).
41+
4142
## Features
4243

4344
OpenNext aims to support all Next.js 14 features. Some features are work in progress. Please open a [new issue](https://github.com/sst/open-next/issues/new) to let us know!
@@ -47,12 +48,12 @@ OpenNext aims to support all Next.js 14 features. Some features are work in prog
4748
- [x] Dynamic routes
4849
- [x] Static site generation (SSG)
4950
- [x] Server-side rendering (SSR)
50-
- [x] [Incremental static regeneration (ISR)](/inner_workings/isr)
51+
- [x] [Incremental static regeneration (ISR)](/inner_workings/caching)
5152
- [x] Middleware
5253
- [x] Image optimization
5354
- [x] [NextAuth.js](https://next-auth.js.org)
54-
- [x] [Running at edge](/advanced/architecture#running-at-edge)
55-
- [x] [No cold start](/inner_workings/warming)
55+
- [x] [Running in lambda@edge](/config/simple_example#running-in-lambdaedge)
56+
- [x] [No cold start](/inner_workings/components/warmer)
5657
- [x] Experimental streaming support
5758

5859
## Who is using OpenNext?

0 commit comments

Comments
 (0)