Skip to content

Commit 66bde34

Browse files
authored
[aws]: Update v2 docs (#124)
1 parent c29add0 commit 66bde34

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

pages/aws/v2.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { Callout } from "nextra/components";
77

88
### Latest Releases
99

10+
- OpenNext [2.3.10](https://www.npmjs.com/package/open-next/v/2.3.10)
1011
- OpenNext [2.3.9](https://github.com/sst/open-next/releases/tag/v2.3.9)

pages/aws/v2/advanced/architecture.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ This ensures that the Lambda handler remains at `index.mjs`.
124124

125125
Create a CloudFront distribution, and dispatch requests to their corresponding handlers (behaviors). The following behaviors are configured:
126126

127-
| Behavior | Requests | CloudFront Function | Origin |
128-
| --------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----------------------------------------------------------------------------------------------------- | --------------------------- |
129-
| `/_next/static/*` | Hashed static files | - | S3 bucket |
130-
| `/favicon.ico`<br />`/my-images/*`<br />[see why](workaround#workaround-public-static-files-served-out-by-server-function-aws-specific) | public assets | - | S3 bucket |
131-
| `/_next/image` | Image optimization | - | image optimization function |
132-
| `/_next/data/*` | data requests | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific) | server function |
133-
| `/api/*` | API | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific) | server function |
134-
| `/*` | catch all | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific) | server function |
127+
| Behavior | Requests | CloudFront Function | Origin |
128+
| --------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
129+
| `/_next/static/*` | Hashed static files | - | S3 bucket |
130+
| `/favicon.ico`<br />`/my-images/*`<br />[see why](workaround#workaround-public-static-files-served-out-by-server-function-aws-specific) | public assets | - | S3 bucket |
131+
| `/_next/image` | Image optimization | - | image optimization function |
132+
| `/_next/data/*` | data requests | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific) | server function |
133+
| `/api/*` | API | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific) | server function |
134+
| `/*` | catch all | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific). Also [see this](workaround#workaround-nextserver-does-not-set-cache-headers-for-html-pages) | server function |
135135

136136
#### Running at edge
137137

pages/aws/v2/advanced/workaround.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,15 @@ export function middleware(request: NextRequest) {
113113

114114
As mentioned in the [Server function](./architecture#server-lambda-function) section, the server function uses the `NextServer` class from Next.js' build output to handle requests. However, `NextServer` does not seem to set the correct `Cache Control` headers.
115115

116-
To work around the issue, the server function checks if the request is for an HTML page, and sets the `Cache Control` header to:
116+
To work around the issue, the server function checks if the request is for a fully static HTML page from page router (i.e. without `getStaticProps`), and sets the `Cache Control` header to:
117117

118118
```
119119
public, max-age=0, s-maxage=31536000, must-revalidate
120120
```
121121

122+
If you plan on using fully static HTML pages, you should also add the `x-middleware-prefetch` header to cloudfront cache headers to avoid cloudfront caching an empty response when this header is set.
123+
You can also just add an empty `getStaticProps` function to your page, which will set the correct cache headers.
124+
122125
#### WORKAROUND: `NextServer` does not set correct SWR cache headers
123126

124127
`NextServer` does not seem to set an appropriate value for the `stale-while-revalidate` cache header. For example, the header might look like this:

0 commit comments

Comments
 (0)