Skip to content

Commit 19f37a2

Browse files
authored
Better docs for config (#417)
* Better docs for config * Added some more example to custom overrides
1 parent 86765bc commit 19f37a2

File tree

5 files changed

+503
-102
lines changed

5 files changed

+503
-102
lines changed

docs/pages/config.mdx

Lines changed: 4 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,108 +7,10 @@ There is a single build argument that you can pass to the `open-next build` comm
77

88
For personalisation you need to create a file `open-next.config.ts` at the same place as your `next.config.js`, and export a default object that satisfies the `OpenNextConfig` interface.
99

10-
Here is a detailed example of an `open-next.config.ts` file:
11-
This file need to be at the same place as your `next.config.js` file
10+
This file needs to be placed at the same level as your `next.config.js` file.
1211

13-
`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)
12+
If you want to take a look at some simple configuration examples, you can check the [simple example](/config/simple_example).
1413

15-
For more information about the options here, take a look at the [components section](/components/overview).
14+
For more advanced use cases, you can check [how to implement custom overrides](/config/custom_overrides).
1615

17-
```ts
18-
import type { OpenNextConfig } from 'open-next/types/open-next'
19-
const config = {
20-
default: { // This is the default server, similar to the server-function in open-next v2
21-
// You don't have to provide the below, by default it will generate an output
22-
// for normal lambda as in open-next v2
23-
override: {
24-
wrapper: "aws-lambda-streaming", // This is necessary to enable lambda streaming
25-
// You can override any part that is a `LazyLoadedOverride` this way
26-
queue: () => Promise.resolve({
27-
send: async (message) => {
28-
//Your custom code here
29-
}
30-
})
31-
},
32-
minify: true, // This will minify the output
33-
},
34-
// Below we define the functions that we want to deploy in a different server
35-
// This is only used if you want to split the server into multiple servers
36-
functions: {
37-
ssr: {
38-
routes: [
39-
"app/api/isr/route", "app/api/sse/route", "app/api/revalidateTag/route", // app dir Api routes
40-
"app/route1/page", "app/route2/page", // app dir pages
41-
"pages/route3" // page dir pages
42-
], // For app dir, you need to include route|page, no need to include layout or loading
43-
patterns: ['api/*', 'route1', 'route2', 'route3'], // patterns needs to be in a cloudfront compatible format, this will be used to generate the output
44-
override: {
45-
wrapper: "aws-lambda-streaming",
46-
},
47-
// This enables the bundled next server which is faster and reduce the size of the server
48-
// This is also experimental and might not work in all cases
49-
experimentalBundledNextServer: true
50-
},
51-
pageSsr: {
52-
routes: ["pages/pageSsr"], // For page dir routes should be in the form `pages/${route}` without the extension, it should match the filesystem
53-
// BUILD_ID is a special case, it will be replaced with the actual build id
54-
patterns: [ 'pageSsr', "_next/data/BUILD_ID/pageSsr.json"],
55-
override: {
56-
wrapper: "node",
57-
converter: "node",
58-
// This is necessary to generate the dockerfile and for the implementation to know that it needs to deploy on docker
59-
// You can also provide a string here which will be used to create the dockerfile
60-
generateDockerfile: true,
61-
},
62-
},
63-
edge: {
64-
runtime: "edge",
65-
routes: ["app/ssr/page"],
66-
patterns: ["ssr"],
67-
override: {}
68-
}
69-
},
70-
// By setting this, it will create another bundle for the middleware,
71-
// and the middleware will be deployed in a separate server.
72-
// If not set middleware will be bundled inside the servers
73-
// It could be in lambda@edge, cloudflare workers, or anywhere else
74-
// By default it uses lambda@edge
75-
// This is not implemented in the reference construct implementation.
76-
// This is optional, but might be necessary if you split your app into multiple servers
77-
middleware: {
78-
external: true
79-
}
80-
81-
// Optional
82-
imageOptimization: {
83-
// This is the architecture of the image, it could be x64 or arm64
84-
// This is necessary to bundle the proper version of sharp
85-
arch: "x64",
86-
}
87-
88-
// If you want to override the default build command, you can do it here
89-
// By default it uses `npm run build`
90-
buildCommand: "echo 'hello world'",
91-
92-
dangerous: {
93-
// This will disable the tag cache
94-
// You can use it safely on page router, on app router it will break revalidateTag and revalidatePath
95-
disableTagCache: true,
96-
// This will disable the incremental cache
97-
// This is generally not recommended, as this is necessary for ISR AND SSG routes as well as the fetch cache
98-
disableIncrementalCache: true,
99-
}
100-
101-
//The path to the target folder of build output from the `buildCommand` option (the path which will contain the `.next` and `.open-next` folders). This path is relative from the current process.cwd() - Optional default to "."
102-
buildOutputPath: "build",
103-
104-
//The path to the root of the Next.js app's source code. This path is relative from the current process.cwd(). - Optional default to "."
105-
appPath: "app",
106-
107-
//The path to the package.json file of the Next.js app. This path is relative from the current process.cwd(). - Optional
108-
packageJsonPath: "package.json",
109-
110-
} satisfies OpenNextConfig
111-
112-
export default config;
113-
export type Config = typeof config
114-
```
16+
If you want to look at a full example, you can check [the full example](/config/full_example).

docs/pages/config/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"simple_example": "Simple Example",
3+
"custom_overrides": "Custom Overrides",
4+
"full_example": "Full Example"
5+
}

0 commit comments

Comments
 (0)