Skip to content

Commit d58fac0

Browse files
committed
updated docs for V3
1 parent 9a6473a commit d58fac0

File tree

6 files changed

+109
-13
lines changed

6 files changed

+109
-13
lines changed

docs/pages/v3/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"index": "What's new",
33
"config": "Configuration file",
44
"reference-implementation": "Reference Construct",
5+
"requirements": "Requirements",
56
"override": "Advanced - Create your own override"
67
}

docs/pages/v3/config.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This file need to be at the same place as your `next.config.js` file
66
For more information about the options here, just look at the source file
77

88
```ts
9-
import type { BuildOptions } from 'open-next/types/open-next'
9+
import type { OpenNextConfig } from 'open-next/types/open-next'
1010
const config = {
1111
default: { // This is the default server, similar to the server-function in open-next v2
1212
// You don't have to provide the below, by default it will generate an output
@@ -62,8 +62,8 @@ const config = {
6262
external: true
6363
}
6464
buildCommand: "echo 'hello world'",
65-
} satisfies BuildOptions
65+
} satisfies OpenNextConfig
6666

67-
module.exports = config
68-
export type OpenNextConfig = typeof config
67+
export default config;
68+
export type Config = typeof config
6969
```

docs/pages/v3/index.mdx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { Callout } from 'nextra/components'
22

33
<Callout type="warning" emoji="⚠️">
44

5-
`[email protected].2` 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)
5+
`[email protected].3` 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)
66

7-
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. See [getting started](#get-started) to quickly test it.
7+
This is a release candidate, it is mostly ready for production (You might still experience some quirks). We are looking for feedback on this release, so please try it out and let us know what you think. See [getting started](#get-started) to quickly test it.
88

99
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+
11+
You could also use SST Ion which should support it out of the box pretty soon. See [here for more info](https://github.com/sst/ion) or in the [ion discord](https://discord.com/channels/983865673656705025/1177071497974648952).
1012
</Callout>
1113

1214
## What's new in V3?
@@ -26,8 +28,13 @@ import { Callout } from 'nextra/components'
2628
- Custom initialization function
2729

2830
- Allow for splitting, you can now split your next app into multiple servers, which could each have their own configuration
31+
- Allow to move the middleware/routing part in a separate lambda or cloudflare workers in front of your server functions
2932
- 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 (Only app router for now, only 1 route per function)
33+
- Experimental support for the `edge` runtime of next with some limitations:
34+
- Only app router for now
35+
- Only 1 route per function
36+
- Works fine in node, only for api route in cloudflare workers
37+
- No support for `revalidateTag` or `revalidatePath` for now
3138

3239
## Get started
3340

@@ -46,13 +53,15 @@ You also need to create an `open-next.config.ts` file in your project root, you
4653
A very simple example of this file could be:
4754

4855
```ts
49-
import type { BuildOptions } from 'open-next/types/open-next'
56+
import type { OpenNextConfig } from 'open-next/types/open-next'
5057
const config = {
5158
default: {
5259

5360
}
5461
}
55-
module.exports = config
62+
export default config;
5663
```
5764

58-
Then you need to run `npx [email protected] build` to build your project before running the `sst deploy` or `cdk deploy` command to deploy your project.
65+
Then you need to run `npx [email protected] build` to build your project before running the `sst deploy` or `cdk deploy` command to deploy your project.
66+
67+
In V3 `open-next build` don't accept any arguments, all the args are passed in the `open-next.config.ts` file.

docs/pages/v3/override.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ A boilerplate for such a plugin could look like this (This is not real code):
1818

1919
```ts
2020

21-
import { BuildOptions } from "open-next/types/open-next";
21+
import { OpenNextConfig } from "open-next/types/open-next";
2222

23-
function withGcp(config: TrimmedDownConfig): BuildOptions {
23+
function withGcp(config: TrimmedDownConfig): OpenNextConfig {
2424
return {
2525
default: {
2626
override: {
@@ -70,5 +70,5 @@ const config = withGcp({
7070
},
7171
});
7272

73-
module.exports = config;
73+
export default config;
7474
```

docs/pages/v3/reference-implementation.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ import {
3838
Distribution,
3939
ICachePolicy,
4040
ViewerProtocolPolicy,
41+
FunctionEventType,
42+
OriginRequestPolicy,
43+
Function as CloudfrontFunction,
44+
FunctionCode,
4145
} from "aws-cdk-lib/aws-cloudfront";
4246
import { HttpOrigin, S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
4347
import {
@@ -347,13 +351,31 @@ export class OpenNextCdkReferenceImplementation extends Construct {
347351
}
348352

349353
private createDistribution(origins: Record<string, HttpOrigin | S3Origin>) {
354+
const cloudfrontFunction = new CloudfrontFunction(this, 'OpenNextCfFunction', {
355+
code: FunctionCode.fromInline(`
356+
function handler(event) {
357+
var request = event.request;
358+
request.headers["x-forwarded-host"] = request.headers.host;
359+
return request;
360+
}
361+
`)
362+
})
363+
const fnAssociations = [
364+
{
365+
function: cloudfrontFunction ,
366+
eventType: FunctionEventType.VIEWER_REQUEST,
367+
},
368+
]
369+
350370
const distribution = new Distribution(this, "OpenNextDistribution", {
351371
defaultBehavior: {
352372
origin: origins.default,
353373
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
354374
allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
355375
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
356376
cachePolicy: this.serverCachePolicy,
377+
originRequestPolicy: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
378+
functionAssociations: fnAssociations
357379
},
358380
additionalBehaviors: this.openNextOutput.behaviors
359381
.filter((b) => b.pattern !== "*")
@@ -372,6 +394,11 @@ export class OpenNextCdkReferenceImplementation extends Construct {
372394
behavior.origin === "s3"
373395
? this.staticCachePolicy
374396
: this.serverCachePolicy,
397+
originRequestPolicy:
398+
behavior.origin === "s3"
399+
? undefined
400+
: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
401+
functionAssociations: fnAssociations
375402
},
376403
};
377404
},

docs/pages/v3/requirements.mdx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
There is a couple of requirements necessary for open-next V3 to work.
2+
It will be divided by functionality. This is still WIP, feel free to open a PR if you think something is missing.
3+
4+
## General
5+
- For the node runtime, you need at least Node 18.
6+
- For the edge runtime, you can use both Node 18+ or cloudflare workers with `node_compat` flag enabled (Cloudflare workers support is experimental)
7+
- Open-next doesn't work well on Windows. We recommend using WSL2 or a Linux VM.
8+
9+
## ISR/SSG
10+
ISR/SSG has 2 types of cache, the Incremental Cache and the Tag Cache. To actually trigger the ISR revalidation, we use a Queue system.
11+
12+
The tag cache is only used in app router.
13+
### Incremental Cache
14+
By default we use S3 as the incremental cache. You can override this in `open-next.config.ts`. For this to work you need to provide server functions with the following environment variables:
15+
- CACHE_BUCKET_REGION
16+
- CACHE_BUCKET_NAME
17+
- CACHE_BUCKET_KEY_PREFIX
18+
19+
### Tag Cache
20+
By default we use DynamoDb as the tag cache. For this to work you need to provide server functions with the following environment variables:
21+
- CACHE_DYNAMO_TABLE
22+
- CACHE_BUCKET_REGION
23+
24+
### Queue
25+
By default we use SQS as the queue. fFr this to work you need to provide server functions with the following environment variables:
26+
- REVALIDATION_QUEUE_REGION
27+
- REVALIDATION_QUEUE_URL
28+
29+
## External Middleware
30+
If you decide to use external middleware, you need to provide the following environment variables:
31+
- OPEN_NEXT_ORIGIN
32+
33+
This env variable should contain a stringified version of this, with every key corresponding to the key used in functions inside `open-next.config.ts`:
34+
```ts
35+
// For cloudflare workers
36+
// THIS IS TEMPORARY, WE WILL CHANGE THIS TO USE THE SAME FORMAT AS NODE
37+
{
38+
default: "example.com",
39+
ssr: "example2.com",
40+
ssg: "example3.com"
41+
}
42+
// Or for node
43+
{
44+
default: {
45+
host: "example.com",
46+
protocol: "https",
47+
port: 443 // Optional
48+
customHeaders: {
49+
"x-custom-header": "value"
50+
} // Optional, headers that you'd want to pass to the origin
51+
},
52+
...
53+
}
54+
```
55+
56+
## Image Optimization
57+
For image optimization to work, you need to provide the following environment variables:
58+
- BUCKET_NAME
59+
- BUCKET_KEY_PREFIX

0 commit comments

Comments
 (0)