SteveLTN / https-portal

A fully automated HTTPS server powered by Nginx, Let's Encrypt and Docker.
MIT License
4.46k stars 295 forks source link

Getting 404 for dynamic Angular Route #285

Closed togacaptain closed 3 years ago

togacaptain commented 3 years ago

So far this has been working great until I added a new dynamic page based on a route param. Whenever I try to navigate directly to the page I get a 404 with nginx reporting that the path or directory couldn't be found.

Based on a little googling it looks like I should be able to update the nginx config to try_files /index.html forcing it to direct to Angular to use the built in routing.

I tried adding the volume mapping of the nginx config files to my docker-compose, but it doesn't appear to be updating the underlying mysite.conf file in the https-portal container.

Not sure how to troubleshoot from here. Looking for a pointer in the right direction.

togacaptain commented 3 years ago

A typo on my part seems to have addressed the nginx config issue. I tried setting redirect to the index.html, but that still isn't working for me. As a workaround I have enabled hash routing in Angular so it looks like "mydomain.com/#/myDynamicPage" this works for my needs so I wanted to share, but long term would still like to get routing working the other way. So thanks for any help in that direction.

SteveLTN commented 3 years ago

I don't think this problem belongs to HTTPS-PORTAL space. HTTPS-PORTAL simply forwards the incoming request to the same path of the upstream, in your case, the Angular app.

I would discourage you from changing the settings in HTTPS-PORTAL to achieve dynamic routing. HTTPS-PORTAL doesn't have access to your Angular app's index.html and it shouldn't. IMO HTTPS-PORTAL should just to one thing. There must be a way to configure your HTTP server of Angular to do this.

How do you run Angular? Since HTTPS-PORTAL is accessing it via HTTP, you must be running some HTTP server. Which one i s that?

togacaptain commented 3 years ago

Need a headslap emoji here. You make an excellent point. I was assuming it was the HTTPS-Portal that was throwing the 404, but it is just routing to another instance of Nginx that is actually serving my Angular app inside my container. Your right if I'm going to change anything then I should change it there as part of my container build.

Thanks for sending me down the right course. Hope anyone else that runs across the same problem in the future will see this and have the same DUH reaction.