serverless-components / website

:zap: Instantly deploy static website on serverless infrastructure with zero configuration using Serverless Components.
https://serverless.com
Apache License 2.0
157 stars 49 forks source link

www -> root domain redirect Cloudfront clash #82

Open vinnyt123 opened 3 years ago

vinnyt123 commented 3 years ago

Following the tutorial for a www -> root domain redirect (e.g www.example.com -> example.com) https://serverless-stack.com/chapters/setup-www-domain-redirect.html, it directs you to set up a new cloudfront distribution for the www subdomain.

This means the www subdomain can no longer be an alternate domain name (CNAME) record for this cloudfront distribution or this error occurs on deploy:

Error: The domain "www.example.com" is already in use by another website or CloudFront Distribution.
    at updateCloudFrontDistribution (/var/task/utils.js:688:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

This is caused by https://github.com/serverless-components/website/blob/6f87650a476e318572209bce9b5403f71643485b/src/utils.js#L103-L104 automatically adding the www alternate domain name (CNAME) record when it is not wanted in this case.

I suggest an option should be added to not include this www alternate domain name (CNAME) for the cloudfront distribution as it makes this style of www redirect impossible.