[Django]-Run EmberJS and Django on the same server and port

3👍

The most common way to do this is to run django and ember on different ports, and use a reverse proxy on port 80 to proxy requests to where you need them to go. Nginx is a popular choice (see http://nginx.com/resources/admin-guide/reverse-proxy/).

An example config of what you want

server {
  listen 127.0.0.1:8080;

  location / {
    proxy_pass http://127.0.0.1:4200; # ember server
    # ... additional proxy config
  }
  location /api {
    proxy_pass http://127.0.0.1:8080; # django server
    # ... additional proxy config
  }
}

Ember CLI can also proxy API request to another server, but I’m not sure about doing it in production.

👤Jakeii

2👍

You are running into problems with the content security policy as described in the ember-cli user guide. You could relax the policy as described here, but I would advise against this.

The ember server command is a simple way to set up a fileserver to test your ember code – but it is not meant for production use. Keep in mind that Ember is meant to be compiled into a javascript asset that you would serve via your backend server or host via a CDN (and reference via a script tag in the html/template that your backend app serves).

For django, this means that you would

  1. compile you ember app into a js file
  2. put it in django’s static dir
  3. reference this js file in your index view
  4. start django as you would normally (but don’t run ember server).

If this is too painful to do in development mode, then I’d recommend playing with the ember server --proxy command. It looks like you could do ember server --proxy 80 and run django on port 80, although this might not work out-of-the-box.

Leave a comment