You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
With this approach you could have a CloudFront distribution in front of the bucket and use a custom domain in the assetPrefix.
120
-
121
120
## Serving static assets
122
121
123
122
Static files can be served by [following the NextJs convention](https://github.com/zeit/next.js/#static-file-serving-eg-images) of using a `static` and `public` folder.
@@ -136,6 +135,23 @@ To serve static files from the root directory you can add a folder called public
136
135
137
136
Note that for this to work, an S3 bucket needs to be provisioned as per [hosting-static-assets](#hosting-static-assets).
138
137
138
+
**For production deployments, enabling CloudFront is recommended:**
139
+
140
+
```yml
141
+
# serverless.yml
142
+
plugins:
143
+
- serverless-nextjs-plugin
144
+
145
+
custom:
146
+
serverless-nextjs:
147
+
assetsBucketName: "your-bucket-name"
148
+
cloudFront: true
149
+
```
150
+
151
+
By doing this, a CloudFront distribution will be created in front of your next application to serve any static assets from S3 and the pages from Api Gateway.
152
+
153
+
Note that deploying the stack for the first time will take considerably longer, as CloudFront takes time propagating the changes, typically 10 - 20mins.
With this approach you could have a CloudFront distribution in front of the bucket and use a custom domain in the assetPrefix.
120
+
## Serving static assets
121
+
122
+
Static files can be served by [following the NextJs convention](https://github.com/zeit/next.js/#static-file-serving-eg-images) of using a `static` and `public` folder.
123
+
124
+
From your code you can then reference those files with a `/static` URL:
To serve static files from the root directory you can add a folder called public and reference those files from the root, e.g: /robots.txt.
135
+
136
+
Note that for this to work, an S3 bucket needs to be provisioned as per [hosting-static-assets](#hosting-static-assets).
120
137
121
-
If you need the static assets available in the main domain of your application, you can use the `routes` configuration to proxy API Gateway requests to S3. For example, to host `/robots.txt`:
138
+
**For production deployments, enabling CloudFront is recommended:**
122
139
123
140
```yml
141
+
# serverless.yml
142
+
plugins:
143
+
- serverless-nextjs-plugin
144
+
124
145
custom:
125
146
serverless-nextjs:
126
-
staticDir: ./assets
127
-
routes:
128
-
- src: ./assets/robots.txt
129
-
path: robots.txt
147
+
assetsBucketName: "your-bucket-name"
148
+
cloudFront: true
130
149
```
131
150
132
-
Note that for this to work, an S3 bucket needs to be provisioned by using the `assetsBucketName` plugin config or `assetPrefix` in `next.config.js`.
151
+
By doing this, a CloudFront distribution will be created in front of your next application to serve any static assets from S3 and the pages from Api Gateway.
152
+
153
+
Note that deploying the stack for the first time will take considerably longer, as CloudFront takes time propagating the changes, typically 10 - 20mins.
133
154
134
155
## Deploying
135
156
@@ -312,15 +333,13 @@ module.exports = page => {
312
333
313
334
## All plugin configuration options
314
335
315
-
| Plugin config key | Default Value | Description |
| nextConfigDir | ./ | Path to parent directory of `next.config.js`. |
318
-
| assetsBucketName |\<empty\>| Creates an S3 bucket with the name provided. The bucket will be used for uploading next static assets. |
319
-
| staticDir |\<empty\>| Directory with static assets to be uploaded to S3, typically a directory named `static`, but it can be any other name. Requires a bucket provided via the `assetPrefix` described above or the `assetsBucketName` plugin config. |
320
-
| routes |[]| Array of custom routes for the next pages or static assets. |
321
-
| customHandler |\<empty\>| Path to your own lambda handler. |
322
-
| uploadBuildAssets | true | In the unlikely event that you only want to upload `static` or `public` dirs, set this to `false`. |
323
-
||
336
+
| Plugin config key | Default Value | Description |
0 commit comments