serverless-next.js
serverless-next.js copied to clipboard
Unable to customize allowed and cached HTTP methods for default behaviour
Issue Summary
I'm trying to customize allowedHttpMethods
and cachedHttpMethods
properties of default caching behaviour.
Reason is I have people running a lot of POST requests on my frontpage bypassing any caching and causing a bill increase because of data transfer and lambda executions.
I'm following docs and setting:
inputs:
cloudfront:
defaults:
allowedHttpMethods: [ 'GET', 'HEAD', 'OPTIONS' ]
cachedHttpMethods: [ 'GET', 'HEAD', 'OPTIONS' ]
Actual behavior
Neither option works. No matter what value I pass the end result in the generated template in .serverless
directory is always:
"defaults": {
"minTTL": 0,
"defaultTTL": 0,
"maxTTL": 31536000,
"allowedHttpMethods": [
"HEAD",
"DELETE",
"POST",
"GET",
"OPTIONS",
"PUT",
"PATCH"
],
"cachedHttpMethods": [
"GET",
"HEAD",
"OPTIONS"
],
"forward": {
"headers": [
"Host",
"Authorization"
],
"cookies": "all",
"queryString": true
},
"queryString": false,
"cookies": "none",
"lambda@edge": {
"origin-request": "xxx",
"origin-response": "xxx"
},
"compress": true
},
It's because both values are hardcoded and ignore any attempt of customization.
allowedHttpMethods
is hardcoded here:
https://github.com/serverless-nextjs/serverless-next.js/blob/ca7f7f72e3b1e5fcb49ffc4a3f6d6f629e644b20/packages/serverless-components/nextjs-component/src/component.ts#L929-L938
cachedHttpMethods
is hardcoded here:
https://github.com/serverless-nextjs/serverless-next.js/blob/04fec27ca99994acf98ccfb4ac6ead933cfb4dde/packages/serverless-components/aws-cloudfront/src/getDefaultCacheBehavior.ts#L46-L49
Is there any reason why are these options set the way they are and cannot be customized?
Expected behavior
Currently hardcoded values should rather be defaults that can be overwritten.
Versions
- OS/Environment: Any
- @sls-next/serverless-component version: 3.7.0
- Next.js version: 11.1.2
Additional context
Checklist
- [x] You have reviewed the README and FAQs, which answers several common questions.
- [x] You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if possible.
- [x] You have first tried using the most recent
latest
oralpha
@sls-next/serverless-component
release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the oldserverless-next.js
component and theserverless-next.js
plugin are deprecated and no longer maintained.
Hello,
Is there's still any workaround ? I'm using websocket and need to add custom headers https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-working-with.websockets.html
Thanks