问题
I have recently been following the two questions to create a website that serves a multitude of static sites from a S3 domain subfolder:
- Serving a multitude of static sites from a wildcard domain in AWS
- Lambda script to direct to fallback S3 domain subfolder when not found
What I failed to realise is that within each sub-domain there is a compiled Angular application present. Angular has SPAs which need to fall back to index.html
mto effectively let the SPA handle routing. My current Cloudfront configuration on the bucket which serves a multitude of static websites prevents this:
The current setup works for an isolated case. For example, in an instance where the user browses to a known existent subdomain e.g. site-does-not-exist.myapps.com
, it will then redirect them to the bucket error-pages - index.html
page, which contains code which then redirects the user back to the parent domain.
However, this means that it sometimes catches false positives, i.e. when the user browses to site-does-exist.myapps.com/about
, then the above rule catches it and directs them to error-pages bucket. This is wrong, it should be directing them to the index.html page of the current bucket.
Does anyone have an idea of how to best resolve this?
来源:https://stackoverflow.com/questions/59986729/fallback-to-s3-website-subfolder-for-angular-spa