Skip to content

Commit 36da819

Browse files
authored
Initial docs for V3 (#330)
* docs for V3 * fix link * clearer routes in config
1 parent ba6e176 commit 36da819

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

docs/pages/v3/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"index": "What's new",
3+
"config": "Configuration file",
4+
"override": "Create your own override"
5+
}

docs/pages/v3/config.mdx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Here is a simple example of an `open-next.config.ts` file:
2+
This file need to be at the same place as your `next.config.js` file
3+
4+
`server` in here could refer to a lambda function, a docker container, a node server or whatever that can support running nodejs code. (Even cloudflare workers in the future)
5+
6+
For more information about the options here, just look at the source file
7+
8+
```ts
9+
import type { BuildOptions } from 'open-next/types/open-next'
10+
const config = {
11+
default: { // This is the default server, similar to the server-function in open-next v2
12+
// You don't have to provide the below, by default it will generate an output
13+
// for normal lambda as in open-next v2
14+
override: {
15+
wrapper: "aws-lambda-streaming", // This is necessary to enable lambda streaming
16+
// You can override any part that is a `LazyLoadedOverride` this way
17+
queue: () => Promise.resolve({
18+
send: async (message) => {
19+
//Your custom code here
20+
}
21+
})
22+
},
23+
},
24+
functions: { // here we define the functions that we want to deploy in a different server
25+
ssr: {
26+
routes: [
27+
"app/api/isr/route", "app/api/sse/route", "app/api/revalidateTag/route", // app dir Api routes
28+
"app/route1/page", "app/route2/page", // app dir pages
29+
"pages/route3" // page dir pages
30+
], // For app dir, you need to include route|page, no need to include layout or loading
31+
patterns: ['api/*', 'route1', 'route2', 'route3'], // patterns needs to be in a cloudfront compatible format, this will be used to generate the output
32+
override: {
33+
wrapper: "aws-lambda-streaming",
34+
},
35+
experimentalBundledNextServer: true // This enables the bundled next server which is faster and reduce the size of the server
36+
},
37+
pageSsr: {
38+
routes: ["pages/pageSsr"], // For page dir routes should be in the form `pages/${route}` without the extension, it should match the filesystem
39+
patterns: [ 'pageSsr', "_next/data/BUILD_ID/pageSsr.json"],
40+
override: {
41+
wrapper: "node",
42+
converter: "node",
43+
generateDockerfile: true,
44+
},
45+
},
46+
},
47+
// By setting this, it will create another bundle for the middleware,
48+
// and the middleware will be deployed in a separate server.
49+
// If not set middleware will be bundled inside the servers
50+
// It could be in lambda@edge, cloudflare workers, or anywhere else
51+
// By default it uses lambda@edge
52+
middleware: {
53+
external: true
54+
}
55+
buildCommand: "echo 'hello world'",
56+
} satisfies BuildOptions
57+
58+
module.exports = config
59+
export type OpenNextConfig = typeof config
60+
```

docs/pages/v3/index.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Callout } from 'nextra/components'
2+
3+
<Callout type="warning" emoji="⚠️">
4+
5+
This is a release candidate, it is not yet ready for production, but we are getting close. We are looking for feedback on this release, so please try it out and let us know what you think.
6+
7+
`[email protected]` is here!!! Please report any issues you find on [discord](https://discord.com/channels/983865673656705025/1164872233223729152) or on the github [PR](https://github.com/sst/open-next/pull/327)
8+
9+
It also requires an updated version of the IAC tools that you use, see the sst PR [here](https://github.com/sst/sst/pull/3567) for more information
10+
</Callout>
11+
12+
## What's new in V3?
13+
14+
- Rewritten server (We moved from the serverless-http `ServerResponse` into our own version which respect nodejs stream)
15+
- A new `open-next.config.ts` file to configure your project
16+
- Native support for aws lambda, aws lambda streaming, lambda@edge, node and docker
17+
- In this `open-next.config.ts` you can now override a lot of things which allow for more customization:
18+
- Wrapper component
19+
- Converter component
20+
- Incremental Cache
21+
- Tag Cache
22+
- Queue
23+
- Custom warmer function
24+
- Custom revalidation function
25+
- Custom loader for image optimization
26+
- Custom initialization function
27+
28+
- Allow for splitting, you can now split your next app into multiple servers, which could each have their own configuration
29+
- An experimental bundled `NextServer` could be used which can reduce the size of your lambda by up to 24 MB
30+
- ~~Support for the `edge` runtime of next~~ (coming soon)

docs/pages/v3/override.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
In this version of open-next, you could override a lot of the default behaviour.
2+
3+
For some real example of how to override each behaviour:
4+
- [Wrapper](https://github.com/conico974/open-next/blob/feat/splitting/packages/open-next/src/wrappers/aws-lambda.ts)
5+
- [Converter](https://github.com/conico974/open-next/blob/feat/splitting/packages/open-next/src/converters/aws-apigw-v2.ts)
6+
- [IncrementalCache](https://github.com/conico974/open-next/blob/feat/splitting/packages/open-next/src/cache/incremental/s3.ts)
7+
- [TagCache](
8+
https://github.com/conico974/open-next/blob/feat/splitting/packages/open-next/src/cache/tag/dynamoDb.ts
9+
)
10+
- [Queue](
11+
https://github.com/conico974/open-next/blob/feat/splitting/packages/open-next/src/queue/sqs.ts
12+
)
13+
14+
This means it could allow people to write their own custom open-next.
15+
For example you could create a custom `withGcp` plugin to allow to deploy open-next on GCP functions
16+
17+
A boilerplate for such a plugin could look like this (This is not real code):
18+
19+
```ts
20+
21+
import { BuildOptions } from "open-next/types/open-next";
22+
23+
function withGcp(config: TrimmedDownConfig): BuildOptions {
24+
return {
25+
default: {
26+
override: {
27+
wrapper: async () => (await import("./gcp-wrapper")).default,
28+
converter: async () => (await import("./gcp-converter")).default,
29+
incrementalCache: async () => (await import("./gcp-incremental-cache")).default,
30+
tagCache: async () => (await import("./gcp-tag-cache")).default,
31+
queue: async () => (await import("./gcp-queue")).default,
32+
},
33+
...config.default,
34+
},
35+
functions: {
36+
// Same as default but for each splitted function
37+
//...
38+
}
39+
warmer: {
40+
override: {
41+
wrapper: async () => (await import("./gcp-wrapper")).default,
42+
converter: async () => (await import("./gcp-converter")).default,
43+
},
44+
invokeFunction: async () => (await import("./gcp-invoke-function")).default,
45+
},
46+
revalidate: {
47+
override: {
48+
wrapper: async () => (await import("./gcp-wrapper")).default,
49+
converter: async () => (await import("./gcp-queue-converter")).default,
50+
},
51+
},
52+
imageOptimization: {
53+
override: {
54+
wrapper: async () => (await import("./gcp-wrapper")).default,
55+
converter: async () => (await import("./gcp-converter")).default,
56+
},
57+
loader: async () => (await import("./gcp-object-loader")).default,
58+
},
59+
}
60+
}
61+
```
62+
63+
Using this plugin would look like this inside `open-next.config.ts`:
64+
65+
```ts
66+
import { withGcp } from "./with-gcp";
67+
const config = withGcp({
68+
default: {
69+
// ...
70+
},
71+
});
72+
73+
module.exports = config;
74+
```

0 commit comments

Comments
 (0)