Fallback to S3 website subfolder for Angular SPA

旧街凉风 提交于 2020-03-06 10:58:30

问题


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.htmlmto 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!