Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Ember CLI with Django app

Before Ember CLI, I use to create an index.html page within Django project, plus the App.js file and all seemed to be working great. Now that Ember is using CLI, it seems that there is no easy way to integrate Ember CLI project within Django application. So I read that people are recommending using Ember CLI to develop the front-end, and Django to develop the REST API. However deployment is not easy, because you need to copy the Ember dist folder under Django static folder, plus change all the static asset url under Ember app to point to Django static path.

So it seems that, there is no easy way to integrate the two into one single development process.

Do you guys, have any suggestions on how to integrate the development, and deployment process?

Thx.

like image 441
Mohamed Termoul Avatar asked Sep 23 '15 17:09

Mohamed Termoul


Video Answer


2 Answers

For projects like this, you should use separate repositories for your server app and client app(s).

Consider a project that has 4 code repositories, 1 server and 3 clients:

  • myproject (A Django app written in Python that provides an API for clients)
  • myproject-web (The Ember.js web client written in JavaScript)
  • myproject-ios (An iOS client app written in Swift)
  • myproject-android (An Android client app written in Java)

The core app will be deployed to a server that is capable of hosting Python apps (e.g. uWSGI).

Because the Ember.js project is ultimately a static resource, you can serve it from pretty much anywhere (e.g. NGINX), and point it at a separate API server that hosts the Django project (e.g. https://app.myproject.com/api/). See documentation on configuring ember-django-adapter to use a custom API host: http://dustinfarris.com/ember-django-adapter/configuring/

iOS of course would be deployed to the Apple App Store, and the Android project would be deployed to Google Play.

Each repository is a separate codebase with different requirements and deployment strategies—which is why it is best to keep them separate, so you can think about them and work with them in isolation. Just because Django can handle static assets doesn't mean you should rely on it—trying to host an Ember.js project (or any other JS framework project) within a Django project is just overcomplicating things. Hope that helps.

like image 156
dustinfarris Avatar answered Sep 21 '22 12:09

dustinfarris


I am currently implementing a Ember-CLI app served by Django.

Here are the steps that I followed:

On Django:

  1. Create a sub-project in your django project (ie: ember)
  2. Install django-redis-views that will serve your index.html from redis.
  3. Create a S3 bucket + CDN on AWS (or other storage product) in order to store your assets

On Ember:

  1. install ember-deploy-redis & ember-deploy-s3
  2. Add credentials to config.deployment and correct fingerprint in your ember-cli-build.js
  3. Deploy ember

Useful link:

  • Easy deployment using redis + CDN: http://ember-cli.github.io/ember-cli-deploy/
  • Pip package that help your retrieving your index.html stored on redis: https://github.com/kevinlondon/django-redis-views
like image 42
mnowik Avatar answered Sep 20 '22 12:09

mnowik