Run EmberJS and Django on the same server and port
I want to run EmberJS and Django on the same server to avoid cross-domain requests.
So for example, I want to run EmberJS on
exemple.com:80
and the Django REST API on
exemple.com:80/api/
I usually start ember with a command ember serve --port 80
and start django with a command python manage.py runserver 0.0.0.0:8000
. But at the same time, the two servers are in different domains and I am having problems with cross doman.
How do I go about running all two on the same server with the same port?
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 wherever you need them. 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
}
}
The Ember CLI can also request a proxy API request to another server, but I'm not sure about making one.
You are having problems with your content security policy as described here , but I would suggest doing it.
The command ember server
is an easy way to set up a file server to test your ember code, but it is not intended to be used for production purposes. Keep in mind that Ember is meant to be compiled into a javascript resource that you will serve through your server or host through the CDN (and link through the script tag in the html / template that your backend application uses).
For django, this means you
- compile your ember app to js file
- put it in django static dir
- refers to this js file in index view.
- start django as usual (but don't start the ember server).
If this is too difficult to do in development mode, I would recommend playing with a command ember server --proxy
. It looks like you could make ember server --proxy 80
and run django on port 80, although that might not work out of the box .