Skip to content

Commit 883c87c

Browse files
committed
Merge branch 'main' of github.com:serverless-stack/open-next
2 parents 321bc21 + db69863 commit 883c87c

File tree

7 files changed

+146
-42
lines changed

7 files changed

+146
-42
lines changed

README.md

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
<p align="center">
2+
<a href="https://open-next.js.org">
3+
<picture>
4+
<source media="(prefers-color-scheme: dark)" srcset="docs/public/logo-dark.svg">
5+
<img alt="OpenNext" src="docs/public/logo-light.svg" width="300" />
6+
</picture>
7+
</a>
8+
</p>
19
<p align="center">
210
<a href="https://sst.dev/discord"><img alt="Discord" src="https://img.shields.io/discord/983865673656705025?style=flat-square" /></a>
311
<a href="https://www.npmjs.com/package/open-next"><img alt="npm" src="https://img.shields.io/npm/v/open-next.svg?style=flat-square" /></a>
412
</p>
513

6-
# OpenNext
14+
---
715

816
OpenNext takes the Next.js build output and converts it into a package that can be deployed to any functions as a service platform.
917

@@ -23,38 +31,38 @@ OpenNext aims to support all Next.js 13 features. Some features are work in prog
2331

2432
1. Naviate to your Next.js app
2533

26-
```bash
27-
cd my-next-app
28-
```
34+
```bash
35+
cd my-next-app
36+
```
2937

3038
2. Ensure [standalone output](https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files) is enabled in your `next.config.js`:
3139

32-
```diff
33-
/** @type {import('next').NextConfig} */
34-
const nextConfig = {
35-
+ output: "standalone"
36-
reactStrictMode: true,
37-
swcMinify: true,
38-
}
40+
```diff
41+
/** @type {import('next').NextConfig} */
42+
const nextConfig = {
43+
+ output: "standalone"
44+
reactStrictMode: true,
45+
swcMinify: true,
46+
}
3947

40-
module.exports = nextConfig
41-
```
48+
module.exports = nextConfig
49+
```
4250

43-
3. Build app
51+
3. Build the app
4452

45-
```bash
46-
npx open-next build
47-
```
53+
```bash
54+
npx open-next build
55+
```
4856

49-
This will generate an `.open-next` directory with the following bundles:
57+
This will generate an `.open-next` directory with the following bundles:
5058

51-
```bash
52-
my-next-app/
53-
.open-next/
54-
assets/ -> Static assets to upload to an S3 Bucket
55-
server-function/ -> Handler code for server Lambda Function
56-
middleware-function/ -> Handler code for middleware Lambda@Edge Function
57-
```
59+
```bash
60+
my-next-app/
61+
.open-next/
62+
assets/ -> Static assets to upload to an S3 Bucket
63+
server-function/ -> Handler code for server Lambda Function
64+
middleware-function/ -> Handler code for middleware Lambda@Edge Function
65+
```
5866

5967
## Recommeded infrastructure
6068

@@ -63,10 +71,10 @@ OpenNext does not create the underlying infrastructure. You can create the infra
6371
This is the recommended setup.
6472

6573
<p align="center">
66-
<img alt="Architecture" src="/readme/architecture.png" width="800" />
74+
<img alt="Architecture" src="docs/public/architecture.png" width="800" />
6775
</p>
6876

69-
A few AWS resources are created:
77+
A few AWS resources need to be created:
7078

7179
- An S3 bucket to host static assets from `.open-next/assets`.
7280
- A Lambda function handling server and API requests.
@@ -76,15 +84,15 @@ A few AWS resources are created:
7684

7785
## How does OpenNext work?
7886

79-
When you call `npx open-next build`, behind the scene OpenNext builds your Next.js app using the `@vercel/next` package. This package does 2 things:
87+
When you call `npx open-next build`, behind the scenes OpenNext builds your Next.js app using the `@vercel/next` package. This package does 2 things:
8088

8189
- It calls `next build` with the [`minimalMode`](https://github.com/vercel/next.js/discussions/29801) flag. This flag disables running middleware in the server code.
8290

8391
- Instead, it bundles the middleware separately. This allows us to deploy middleware to edge locations.
8492

8593
Then `open-next` transforms `@vercel/next`'s build output into a format that can be deployed to AWS. The following steps are performed:
8694

87-
1. Creates a `.open-next` directory in user's Next.js app.
95+
1. Creates a `.open-next` directory in the user's Next.js app.
8896

8997
1. Bundles the middleware handler with the [middleware adapter](/cli/assets/middleware-adapter.js). And outputs the handler file into `.open-next/middleware-function`.
9098

@@ -98,7 +106,7 @@ Then `open-next` transforms `@vercel/next`'s build output into a format that can
98106

99107
## Example
100108

101-
In the `example` folder, you can find a benchmark Next.js app. Here is a link deployed using SST's [`NextjsSite`](https://docs.sst.dev/constructs/NextjsSite) construct. It contains a handful of pages. Each page aims to test a single Next.js feature.
109+
In the `example` folder, you can find a benchmark Next.js app. Here's a link deployed using SST's [`NextjsSite`](https://docs.sst.dev/constructs/NextjsSite) construct. It contains a handful of pages. Each page aims to test a single Next.js feature.
102110

103111
## Debugging
104112

@@ -114,8 +122,12 @@ Create a PR and add a new page to the benchmark app in `example` with the issue.
114122

115123
#### Why use the `@vercel/next` package for building the Next.js app?
116124

117-
`next build` generates a server function that runs middleware. With this setup, if you use middleware for static pages, these pages cannot be cached. If cached, CDN (CloudFront) will send back cached response without calling the origin (server Lambda function). To ensure the middleware is invoked on every request, caching is always disabled.
125+
The `next build` command generates a server function that runs the middleware. With this setup, if you use middleware for static pages, these pages cannot be cached. If cached, CDN (CloudFront) will send back the cached response without calling the origin (server Lambda function). To ensure the middleware is invoked on every request, caching is always disabled.
118126

119-
Vercel deploys the middleware code to edge functions, which gets invoked before the request reaches the CDN. This way, static pages can be cached. On request, middleware gets called, and then the CDK can send back cached response.
127+
Vercel deploys the middleware code to edge functions, which gets invoked before the request reaches the CDN. This way, static pages can be cached. On request, the middleware gets called, and then the CDN can send back the cached response.
120128

121129
OpenNext is designed to adopt the same setup as Vercel. And building using `@vercel/next` allows us to separate the middleware code from the server code.
130+
131+
---
132+
133+
Maintained by [SST](https://sst.dev). Join our community: [Discord](https://sst.dev/discord) | [YouTube](https://www.youtube.com/c/sst-dev) | [Twitter](https://twitter.com/SST_dev)

docs/pages/index.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export default function Home() {
1414

1515
<h2 className={styles.description}>{SITE.description}</h2>
1616

17+
<section className={styles.cta}>
18+
<a href={SITE.github}>Star us on GitHub</a>
19+
<a href={`${SITE.github}/blob/main/README.md`}>View README</a>
20+
</section>
21+
1722
<div className={styles.divider}></div>
1823

1924
<section className={styles.about}>
@@ -22,8 +27,8 @@ export default function Home() {
2227
that can be deployed to any functions as a service platform.
2328
</p>
2429
<p>
25-
It supports all Next.js 13 features including, SSG, ISR, SSR, Image
26-
Optimization, and Middleware.
30+
The goal is to support all Next.js 13 features including, SSG, ISR,
31+
SSR, Image Optimization, and Middleware.
2732
</p>
2833
</section>
2934

@@ -53,8 +58,8 @@ export default function Home() {
5358
</p>
5459
<p>
5560
Next.js, unlike Remix or Astro, doesn't have a way to self-host using
56-
serverless. You can only run it in a Docker container. Containers are
57-
expensive and need to be scaled.
61+
serverless. You can run it as a Node application. This however doesn't
62+
work the same way as it does on Vercel.
5863
</p>
5964
</section>
6065

@@ -100,6 +105,10 @@ export default function Home() {
100105
The goal of OpenNext is to create an open source, framework agnostic,
101106
serverless adapter for Next.js.
102107
</p>
108+
<p>
109+
OpenNext is currently built for AWS but we plan to support any
110+
functions as a service platform.
111+
</p>
103112
<p>
104113
We need your help keeping it up to date and feature complete. Make
105114
sure to{" "}
@@ -166,14 +175,14 @@ export default function Home() {
166175
<ol>
167176
<li>
168177
<p>
169-
Run <code>open-next build</code> to generate the <code>.open-next</code>{" "}
170-
directory.
178+
Run <code>open-next build</code> to generate the{" "}
179+
<code>.open-next</code> directory.
171180
</p>
172181
<p>
173-
This directory contains a zip
174-
file of your app that'll run in a Lambda function, a zip file
175-
that'll run the middleware Lambda@Edge function, and a zip fileectory
176-
containing your static assets that'll go to S3.
182+
This directory contains a zip file of your app that'll run in a
183+
Lambda function, a zip file that'll run the middleware Lambda@Edge
184+
function, and a zip fileectory containing your static assets
185+
that'll go to S3.
177186
</p>
178187
</li>
179188
<li>
File renamed without changes.

docs/public/logo-dark.svg

Lines changed: 10 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)