Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit e7bed6a

Browse files
authored
feat(serverless-component): allow custom configuration for Cloudfront (#282)
1 parent 86228a3 commit e7bed6a

File tree

10 files changed

+557
-137
lines changed

10 files changed

+557
-137
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ sls-next-build
1313
yarn.lock
1414
dist
1515
.vscode
16+
.env

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ A zero configuration Nextjs 9.0 [serverless component](https://github.com/server
1717
- [Getting started](#getting-started)
1818
- [Lambda@Edge configuration](#lambda-at-edge-configuration)
1919
- [Custom domain name](#custom-domain-name)
20+
- [Custom CloudFront configuration](#custom-cloudfront-configuration)
2021
- [AWS Permissions](#aws-permissions)
2122
- [Architecture](#architecture)
2223
- [Inputs](#inputs)
@@ -98,8 +99,9 @@ In most cases you wouldn't want to use CloudFront's distribution domain to acces
9899

99100
You can use any domain name but you must be using AWS Route53 for your DNS hosting. To migrate DNS records from an existing domain follow the instructions
100101
[here](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html). The requirements to use a custom domain name:
101-
* Route53 must include a _hosted zone_ for your domain (e.g. `mydomain.com`) with a set of nameservers.
102-
* You must update the nameservers listed with your domain name registrar (e.g. namecheap, godaddy, etc.) with those provided for your new _hosted zone_.
102+
103+
- Route53 must include a _hosted zone_ for your domain (e.g. `mydomain.com`) with a set of nameservers.
104+
- You must update the nameservers listed with your domain name registrar (e.g. namecheap, godaddy, etc.) with those provided for your new _hosted zone_.
103105

104106
The serverless next.js component will automatically generate an SSL certificate and create a new record to point to your CloudFront distribution.
105107

@@ -123,6 +125,28 @@ myNextApplication:
123125
domain: ["sub", "example.com"] # [ sub-domain, domain ]
124126
```
125127

128+
### Custom CloudFront configuration
129+
130+
To specify your own CloudFront inputs, just add any [aws-cloudfront inputs](https://github.com/serverless-components/aws-cloudfront#3-configure) under `cloudfront`:
131+
132+
```yml
133+
# serverless.yml
134+
135+
myNextApplication:
136+
component: serverless-next.js
137+
inputs:
138+
cloudfront:
139+
my-page/*:
140+
ttl: 0
141+
forward:
142+
cookies: "all"
143+
queryString: false
144+
my-other-page:
145+
viewerProtocolPolicy: redirect-to-https
146+
```
147+
148+
This is particularly useful for caching any of your next.js pages at CloudFront's edge locations. See [this](/https://github.com/danielcondemarin/serverless-next.js/tree/master/packages/serverless-component/examples/app-with-custom-caching-config) for an example application with custom cache configuration.
149+
126150
### AWS Permissions
127151

128152
By default the Lambda@Edge functions run using AWSLambdaBasicExecutionRole which only allows uploading logs to CloudWatch. If you need permissions beyond this, like for example access to DynamoDB or any other AWS resource you will need your own custom policy arn:
@@ -229,6 +253,7 @@ The fourth cache behaviour handles next API requests `api/*`.
229253
| build.cwd | `string` | `./` | Override the current working directory |
230254
| build.enabled | `boolean` | `true` | Same as passing `build:false` but from within the config |
231255
| build.env | `object` | `{}` | Add additional environment variables to the script |
256+
| cloudfront | `object` | `{}` | Inputs to be passed to [aws-cloudfront](https://github.com/serverless-components/aws-cloudfront) |
232257

233258
Custom inputs can be configured like this:
234259

package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)