Serving Angular + Django with unit

Tobias Genannt tobias.genannt at kappa-velorum.net
Thu Jan 21 12:51:15 UTC 2021


Hello,

I'm serving an Angular + Django app with unit. For the most parts this 
is working fine. The problem I'm having is with deep links and the 
angular router.

All request to paths that are not found should be served the index.html 
so that the Angular router can activate the matching component. In nginx 
I would do this with the following:

try_files $uri $uri/ /index.html;

In unit I'm currently using this:

"routes": [
     {
         "match": {
             "uri": [
                 "/api/*",
                 "/admin/*"
             ]
         },
         "action": {
             "pass": "applications/myapp"
         }
     },

     {
         "action": {
             "share": "/opt/myapp/web",
             "fallback": {
                 "return": 301,
                 "location": "/"
             }
         }
     }
],

With this configuration I'm loosing the path information because of the 
redirect.

Any tips on how to solve the problem? Is there a way to get unit to 
behave like try_files in nginx?

Kind regards,
Tobias


More information about the unit mailing list