This is the main entrypoint of the server. It is used for every server and allow you to run either in serverless mode or as a long running server.
If you want to better understand how to implement your own Wrapper, the easiest way would be to take a look at one of the existing included Wrapper (opens in a new tab).
Couple of things to note :
- If you want to use streaming (for the
noderuntime of next), you'll need to create aStreamCreatorand pass it to thehandler. You can find some example in the node (opens in a new tab) or aws-lambda-streaming (opens in a new tab) wrapper. - If you don't use streaming (like in the default
aws-lambdawrapper), you may still need to provide a fakeStreamCreatorto thehandlerto avoid a weird issue with Node itself (see here (opens in a new tab) for an example and a more thorough explanation). - If you use the
edgeruntime of Next (either for the external middleware or for anedgeroute or page), you don't need theStreamCreatorat all. - If you are in a serverless environment and it supports
waitUntil, you should pass it to the handler as it is done in the cloudflare-edge wrapper (opens in a new tab). Theaws-lambda-streamingandaws-apigw-streamingwrappers provide their ownwaitUntil(pending promises are awaited before the response stream is closed). This might not be necessary depending on where you run it (for example thenodewrapper doesn't need it as it is a long running server.)
Included Wrappers
aws-lambda
The aws-lambda Wrapper is the default wrapper for AWS Lambda. It is used by default if you don't provide any Wrapper in your configuration.
Features
- Streaming
- Proper support for
waitUntil
aws-lambda-streaming
The aws-lambda-streaming Wrapper is a wrapper that allows you to use streaming in AWS Lambda. Streaming must be enabled for this lambda and it must be invoked through a Lambda Function URL.
The response is compressed (br, gzip or deflate) according to the Accept-Encoding header of the request.
Features
- Streaming
- Proper support for
waitUntil(available since@opennextjs/aws4.1.6) - Compression
aws-apigw-streaming
Available since @opennextjs/aws 4.1.0
The aws-apigw-streaming Wrapper allows you to use streaming when the server function is behind an API Gateway REST API with response streaming (opens in a new tab) (ResponseTransferMode: STREAM) instead of a Lambda Function URL.
It should be used with the aws-apigw-v1 (REST API) or aws-apigw-v2 (HTTP API) converter.
Unlike aws-lambda-streaming, it never compresses the response because API Gateway streaming does not support content encoding. Compression should be handled by the CDN in front of API Gateway (e.g. CloudFront).
Features
- Streaming
- Proper support for
waitUntil - Compression
aws-lambda-compressed
Available since @opennextjs/aws 3.5.6
The aws-lambda-compressed Wrapper is the same as the aws-lambda Wrapper but it also compresses the response (br, gzip or deflate) according to the Accept-Encoding header of the request.
It can be useful to reduce the size of the response as AWS Lambda has a limit of 6MB for the response payload.
Features
- Streaming
- Proper support for
waitUntil - Compression
Compression
The Brotli compression quality used by the aws-lambda-streaming and aws-lambda-compressed wrappers can be set with the BROTLI_QUALITY environment variable (from 0 to 11). It defaults to 6.
cloudflare-edge
The cloudflare-edge Wrapper is the wrapper for Cloudflare Workers. It should be used for the external middleware and for the edge runtime of Next.
Features
- Streaming
- Proper support for
waitUntil
cloudflare-node
The cloudflare-node Wrapper is the wrapper for Cloudflare Workers. It should be used only with the node runtime of Next and if you use @opennextjs/cloudflare.
Features
- Streaming
- Proper support for
waitUntil
node
The node Wrapper is the wrapper for classic Node.js Server. This one is a long running server.
Features
- Streaming
- Proper support for
waitUntil
express-dev
The express-dev Wrapper is the wrapper for a classic Express server. It is a long running process and should be used for development purposes only.
Features
- Streaming
- Proper support for
waitUntil
dummy
The dummy Wrapper is a dummy implementation that will just forward the event and StreamCreator to the handler.
Features
- Streaming
- Proper support for
waitUntil