Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom config for all cloudfront inputs #282

Merged
merged 47 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
40e7f21
allow custom cloudfront config
stan-sack Jan 18, 2020
5680f90
move cloudfront config generation to after lambda arn is known
stan-sack Jan 20, 2020
483d04a
add tests and update readme
stan-sack Jan 20, 2020
7c2c9b3
update main readme
stan-sack Jan 20, 2020
da1706f
commit test md
stan-sack Jan 20, 2020
a1521c5
remove test list item
stan-sack Jan 20, 2020
41a0489
pull upstream master and handle merge conflicts
stan-sack Mar 12, 2020
64bc744
WIP
stan-sack May 2, 2020
8cac047
Revert "WIP"
stan-sack May 2, 2020
09a32ce
pull upstream and handle merge conflicts
stan-sack May 2, 2020
3dc8180
pull upstream and handle merge conflicts
stan-sack May 2, 2020
0978004
dont append lambda@origin to _next and static
stan-sack May 2, 2020
fc533b6
fix lintin
stan-sack May 2, 2020
f9e96d0
revert changes to lambda-at-edge/package.json
stan-sack May 2, 2020
5bceeae
revert changes to package files
stan-sack May 2, 2020
4a3880d
update jest extended to latest
stan-sack May 2, 2020
343e979
implement gehan's changes. Fix tests. move my own tests into existing…
stan-sack May 5, 2020
5a415c0
fix linting
stan-sack May 5, 2020
8ba5413
remove jest extended as a dep
stan-sack May 5, 2020
cc015ad
commit changes to package lock
stan-sack May 5, 2020
bb5667b
pull upstream and handle merge conflicts
stan-sack May 5, 2020
8db8556
install @sls-next/s3-static-assets as it's required to run the tests
stan-sack May 5, 2020
ae71b2a
fix linting
stan-sack May 5, 2020
59cdf56
Merge branch 'master' of https://github.com/danielcondemarin/serverle…
stan-sack May 5, 2020
f383fb8
Merge branch 'master' of https://github.com/danielcondemarin/serverle…
stan-sack May 7, 2020
529d384
add validation step and update tests
stan-sack May 7, 2020
2c12bf4
pull upstream and fix linting
stan-sack May 7, 2020
f6a866c
remove old path vars
stan-sack May 7, 2020
2c3a8e4
remove s3-static-assets from package.json
stan-sack May 7, 2020
a711e1f
tidy up custom domain input tests
danielcondemarin May 8, 2020
6b718b6
tidy up custom lambda name tests
danielcondemarin May 8, 2020
addc1f5
better comments for each cloudfront custom input test case
danielcondemarin May 8, 2020
92bbfa0
better var names
danielcondemarin May 8, 2020
812d14b
better description
danielcondemarin May 8, 2020
ed1735c
fix typo
May 8, 2020
fc93298
Merge branch 'master' of https://github.com/danielcondemarin/serverle…
May 8, 2020
32d9bd0
dont allow overriding on origin-response
stan-sack May 9, 2020
8d892e7
WIP test
stan-sack May 9, 2020
122d673
fix tests
stan-sack May 9, 2020
555ba9d
use jest.describe.eachi consistent with other tests
danielcondemarin May 9, 2020
ea1a8e1
small tweaks to tests and error messaging
danielcondemarin May 9, 2020
28e72e7
consistent comments casing
danielcondemarin May 9, 2020
4a0ab4a
create common fn for reusing sls component deps
danielcondemarin May 9, 2020
ec7cc5b
remove superfluous mock and tidy up fixture usage
danielcondemarin May 9, 2020
db955ac
add example application with cache settings
danielcondemarin May 9, 2020
bcb0bd5
update docs
danielcondemarin May 9, 2020
c68c219
Merge branch 'master' of https://github.com/danielcondemarin/serverle…
danielcondemarin May 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ sls-next-build
yarn.lock
dist
.vscode
.env
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A zero configuration Nextjs 9.0 [serverless component](https://github.com/server
- [Getting started](#getting-started)
- [Lambda@Edge configuration](#lambda-at-edge-configuration)
- [Custom domain name](#custom-domain-name)
- [Custom CloudFront configuration](#custom-cloudfront-configuration)
- [AWS Permissions](#aws-permissions)
- [Architecture](#architecture)
- [Inputs](#inputs)
Expand Down Expand Up @@ -98,8 +99,9 @@ In most cases you wouldn't want to use CloudFront's distribution domain to acces

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
[here](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html). The requirements to use a custom domain name:
* Route53 must include a _hosted zone_ for your domain (e.g. `mydomain.com`) with a set of nameservers.
* You must update the nameservers listed with your domain name registrar (e.g. namecheap, godaddy, etc.) with those provided for your new _hosted zone_.

- Route53 must include a _hosted zone_ for your domain (e.g. `mydomain.com`) with a set of nameservers.
- You must update the nameservers listed with your domain name registrar (e.g. namecheap, godaddy, etc.) with those provided for your new _hosted zone_.

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

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

### Custom CloudFront configuration

To specify your own CloudFront inputs, just add any [aws-cloudfront inputs](https://github.com/serverless-components/aws-cloudfront#3-configure) under `cloudfront`:

```yml
# serverless.yml

myNextApplication:
component: serverless-next.js
inputs:
cloudfront:
my-page/*:
ttl: 0
forward:
cookies: "all"
queryString: false
my-other-page:
viewerProtocolPolicy: redirect-to-https
```

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.

### AWS Permissions

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:
Expand Down Expand Up @@ -229,6 +253,7 @@ The fourth cache behaviour handles next API requests `api/*`.
| build.cwd | `string` | `./` | Override the current working directory |
| build.enabled | `boolean` | `true` | Same as passing `build:false` but from within the config |
| build.env | `object` | `{}` | Add additional environment variables to the script |
| cloudfront | `object` | `{}` | Inputs to be passed to [aws-cloudfront](https://github.com/serverless-components/aws-cloudfront) |

Custom inputs can be configured like this:

Expand Down
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading