|
| 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 | +``` |
0 commit comments