Simoyw Simoyw - 1 month ago 40
reST (reStructuredText) Question

Run EmberJS and Django on the same server and port

I want to run EmberJS and Django on the same server for avoid to have cross-domain requests.

So, for exemple, I want to run EmberJS on


exemple.com:80


and Django REST API on


exemple.com:80/api/


I normally start ember with command
ember serve --port 80
and a run django with command
python manage.py runserver 0.0.0.0:8000
. But doing this the two server are on different domain and I have cross doman problems.

How can I do to run all two on same server with same port?

Answer Source

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.