Hello,
I have setup a modern web application in PA with a Flask backend + Angular 6 frontend. I have it almost ready to go live but need to configure the web-server to allow the following behaviour:
- Flask listens to all URLs in mydomain.com/api/** and returns with an appropriate JSON. This is working OK
- Angular should listen to all the other routes. In order to achieve this:
- a ) I have created a static file redirect in PA from my angular folder to the root of the domain, so that when someone navigates to mydomain.com the index.html of angular is served. This is working OK.
- b) Since angular is a Single Page Application (SPA), the index.html is the only html that does exist, but it is designed to handle all routes (with and without hashtags). So if I navigate to mydomain.com/products/beef angular will render a page for beef products. Now, in order to achieve this, the PythonAnywhere webserver has to return, for all 404 not found URLs the /index.html in the domain root, so that the Angular SPA can handle the rest. This is the point where I am struggling as I do not see the way to configure the webserver to return the /index.html on any 404. Please let me know how can I achieve this.
Please find in the following link some examples from the Angular team on how to do this for Apache, Nginx or IIS: https://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml
Thank you