0

I have a Angular App with a lot of routes, that run over a Express Server.

Since all routes are from the same one-page-application, I configured Express the return always the same index.html for a bunch of routes, like /login and /settings. And I also have custom routes like /user/:userId.

But since we remove our backend logic to a separated API, we plan to move our files into a Amazon CDN, CloudFront.

But the thing is, CDN works like directories, there is a way to configure CloudFront to point all request without extension to return the index.html? Because that way all .js and .css would work nicely.

I appreciate any help! Thanks.

Update 1

I did some more digging into Aws, and apparently this is more a S3 configuration than CloudFront. But I still don't know how to do this.

Update 2

I already found the answer in this stack.

The solution is tricky, I just had to configure all 404 errors (403 in the case of S3) to redirect to the index.html returning the status code 200, and all worked fine.

Community
  • 1
  • 1
daymannovaes
  • 1,416
  • 12
  • 23
  • CDN are for static files. Do you mean index.html is a template with dynamic content of home and settings route ? – Sylwit Aug 22 '16 at 12:32
  • No, all my files are statics, also `index.html`. The views (home, settings) are loaded dynamically with Angular Route. – daymannovaes Aug 22 '16 at 12:38
  • As noted in your update, you can't move files "into" CloudFront. CloudFront is a cache -- it has no persistent storage. You still need to store them on an origin server, somewhere -- commonly, this is S3. CloudFront doesn't interpret URLs, it passes them through to the origin server. This seems to be a case where you are asking one question, but you may actually need to be asking a different question altogether. – Michael - sqlbot Aug 22 '16 at 22:14
  • 2
    Yes @Michael-sqlbot, you're right. In fact I already found the answer [here](http://stackoverflow.com/questions/16267339/s3-static-website-hosting-route-all-paths-to-index-html) – daymannovaes Aug 24 '16 at 00:40

0 Answers0