Reputation: 691
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?
Upvotes: 3
Views: 868
Reputation: 2285
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
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.
Upvotes: 2
Reputation: 1273
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.
Upvotes: 3