How to serve angular using Django server? I don't want to host two different server for angular and Django. How to do it with a single django server? I have developed frontend application using angular 6 and backend using DRF. I am running django server in the back end and using ng serve command to run angular application.
-
Write the docker file for django and angular and use it. Use webapack to build and integrate with django and run it.Seenu S– Seenu S2019-09-18 15:05:57 +00:00Commented Sep 18, 2019 at 15:05
-
How you want to deploy your Django app? using gunicorn + nginx? If yes then you can use that nginx to serve your Angular projectToan Quoc Ho– Toan Quoc Ho2019-09-18 15:08:42 +00:00Commented Sep 18, 2019 at 15:08
-
@Ton quoc Ho. How to serve angular using nginx?user8106849– user81068492019-09-18 15:19:21 +00:00Commented Sep 18, 2019 at 15:19
-
Just build your angular app into a bundled version. Then on nginx, using reverse proxy to route requests to your django app on path /api/, then route / to index.html (which created by Angular build). Here is an example gist.github.com/lciolecki/a82c4e5f250bfa5c7d63d1b7f65d5a0cToan Quoc Ho– Toan Quoc Ho2019-09-18 16:01:42 +00:00Commented Sep 18, 2019 at 16:01
Add a comment
|
1 Answer
To achieve this, you should serve your Angular project in production mode. This is a must have if you seriously deploy your project to the world, Angular will optimize the bundle to make UX better than on development mode.
And also for Django project, you should deploy it using gunicorn or uwsgi and using nginx as a reverse proxy (reference this gist) for your application.
Hope that helps!