lambda-edge-nice-urls | Static website hosting on S3 via AWS Cloud Front | Cloud Functions library
kandi X-RAY | lambda-edge-nice-urls Summary
kandi X-RAY | lambda-edge-nice-urls Summary
This is an AWS Lambda@Edge function to enable static website hosting on AWS S3 via CloudFront with beautiful page URLs without .html suffixes and without requiring other hacks.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lambda-edge-nice-urls
lambda-edge-nice-urls Key Features
lambda-edge-nice-urls Examples and Code Snippets
Community Discussions
Trending Discussions on lambda-edge-nice-urls
QUESTION
I have an application that uses NextJS as a wrapper, and I make use of NextJS's dynamic routing feature. I had a problem when deploying it to CloudFront due to dns.com/path/page
not being rendered, instead CloudFront expected it to be dns.com/path/page.html
. I worked it around by applying this lambda-edge-nice-url solution. It works properly now. However, there's still one issue left: NextJS's dynamic routes. dsn.com/path/subpath/123
should work, since 123 is a dynamic parameter. However, that does no work. In only returns the page when I access dns.com/path/subpath/[id]
, which of course is not correct, since [id] is not a parameter I want to load.
The strangest thing is: if I try to access the URL as I stated above directly, it fails. However, inside the application I have buttons and links that redirect the user, and that works properly.
Navigating from inside the application (button with router.push
inside its callback):
Trying to access the url directly:
Can anyone help me to properly route the requests?
...ANSWER
Answered 2021-Nov-24 at 21:59I use a CloudFront Lambda@Edge origin request function to handle re-writing both my dynamic routes as well as static routes to the appropriate HTML file so that CloudFront can serve the intended file for any paths.
My lambda function looks like
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lambda-edge-nice-urls
Adjust the function code lambdaRewrite.js and/or its config options as required and upload (or copy-paste) it to your Lambda function.
Publish the Lambda function as a new version.
Add trigger "CloudFront", associate with the CloudFront distribution and the distribution's cache behaviour of your choice (e.g. "*") and select "Origin Request" as CloudFront event.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page