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?
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.
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
compile you ember app into a js file
put it in django's static dir
reference this js file in your index view
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.
Related
I have created Django and VueJS integrated project using webpack_loader.
Django runs at localhost 8000 and VueJS at 8080 port. But port 8000 gives me an error in console that
GET http://0.0.0.0:8080/app.js net::ERR_ADDRESS_INVALID
as I am learning to integrate this two framework together, I followed a tutorial as mention below for this project
https://medium.com/#rodrigosmaniotto/integrating-django-and-vuejs-with-vue-cli-3-and-webpack-loader-145c3b98501a
Thanks in advance
I have checked http://localhost:8080/app.js and it renders a large file, so how come port 8000 cannt connect with it ?
and I have done following changes too
in vue.config.js
change: baseUrl: “http://0.0.0.0:8080/",
to: baseUrl: “http://127.0.0.1:8080/",
and in settings.py change the CACHE value to not DEBUG
replace all areas of “http://0.0.0.0:8080/" with “http://127.0.0.1:8080/" in your frontend app
I developed an app and I want to deploy it on a server. For backend I use Django and for frontend React. The communication between React and Django is via rest api. I also have an Arduino which communicates with Django via rest. I use nginx on server. What is the best way how to deploy this app? Thanks a lot
Well you need a server, popular choices to rent one are AWS or Heroku. Both have a free limited trial and tutorials that explain to you how to deploy your project. Heroku should be a easier to use, while AWS provides more features. Links:
-AWS Elastic Beanstalk: https://aws.amazon.com/it/elasticbeanstalk/
-Heroku: https://www.heroku.com
There are lots of available alternatives of build and orchestration tools.
For example Ansible has many modules for django, nginx, npm, databases... that allow to perform any actions and commands whatever you want. Just configure some webhooks in your repository settings so you could trigger autodeploy by pushing new changes or run it manually if needed.
What i did was use my VPS to host the Django app, and then used graphql (similar to REST) to communicate from React to Django.
The general steps are:
1) on the VPS server, you will have a code directory w/ your Django app, like on your local machine. Just use git to get it there.
2) create a virtualenv on the VPS server with all your needed django/python modules (added via pip) in your code directory
3) create an nginx conf file. i use nginx to proxy_pass to apache, which calls the python app. my nginx listens on port 80, and has a line this this: proxy_pass http://admin.mysite.com:81;. Create a link to this config in /etc/nginx/sites-enabled/ and restart nginx.
4) create an apache conf file with <VirtualHost *:81> with key lines such as: WSGIDaemonProcess and WSGIScriptAlias which point to your virtual env and your wsgi.py file. make sure to enable this too ('a2ensite`).
5) your project's wsgi.py file will point to your app's settings.
6) restart apache and nginx.
That's the real rough outline, and there are tutorials written. Just search for 'django uwsgi nginx' and that will get your django app running, with the proper endpoints for your react app to call.
you can use 1 server with nginx and gunicorn and make the axios to point to localhost for the react app, create 1 gunicorn for the django and 2 nginx 1 for the django and the other for the react,
Gunicorn use the socket and service file you can use the below link (it will help you for the deployment of django):
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
for the react app it is easier, you can make the build on your local and clone the project on the server (make the app to point to localhost)
just create nginx file with the belw:
server {
server_name yourdomain.com;
root /project-path/;
index index.html index.htm;
location / {
try_files $uri /index.html =404;
}
}
I implement a Django website behind a NGINX configured as reverse proxy which serve also the static for Django when it is out of debug mode, all this is in a docker-compose app.
I know by read the Django docs they do not recommend to use integrated web server in a production environment (and it is not at the moment), put it behind a reverse proxy is acceptable to avoid security issue or it is the same as expose it directly?
If it is not an acceptable solution, could you suggest any implementation to not use the Django integrated web server?
Consider that the container structure like the following:
Proxy is the NGINX Official image
www1 & www2 are Python3 Official image with Django installed as described here.
database is the Postgres Official image.
Only the Proxy container is exposed to the external world.
Thanks.
I get my answer, I gonna use gunicorn instead the integrated Django web browser.
I had use documentation present here That describe how to configure gunicorn and nginx on the same host, but using http instead linux socket, instead the command to run the Django integrate web server I have just to run gunicorn like this:
gunicorn --workers=4 --bind=0.0.0.0:9000 --access-logfile - --error-logfile - --log-level debug myapp.wsgi:application
with the previous command I also get logs managed by container.
Off course I also add gunicorn in the requirement file.
I hope this question will help also some one else.
I'm new to web development and deployment however I developed a web site using Python 2.7 and Flask. I can't get the site to load when the user hits the site. When testing on the server using SSH the program starts like it did on my development PC but does not render the first template and shows this error: WARNING: Do not use the development server in a production environment. Use a production WSGI server instead.
In researching that error I found an article that says Flask is not meant for a multi-user public web environment. Further investigation said: If you want to run Flask in production, be sure to use a production-ready web server like Nginx, and let your app be handled by a WSGI application server like Gunicorn.
I think what this is telling me is:
Find a provider that supports Nginx.
Install Gunicorn and then configure it to run on that host.
Doing that should allow my program to run on the host server and be accessible to the world.
Would folks with experience with Python/Flask web apps please confirm the direction I should be heading as I can't afford to go down the wrong path again.
I want to setup django test server so it can be accessed through web address (mainly for facebook testing). For this I'm using the no-ip service wich works fine with apache. But when I try starting the test server on port 80 access from the same web URL gives Problem loading page.
I've already concluded that the router is properly configured (port forwarding works with apache) and that the test server is running locally.
So what should I do? Do you have any suggestions about developing django project with facebook integration?
Thanks!
I would also recommend using the localtunnel Ruby gem. It will provide you with a publicly accessible web address that routes requests to a locally bound port:
$ python manage.py runserver
$ localtunnel 8000
This localtunnel service is brought to you by Twilio.
Port 8000 is now publicly accessible from http://qw1e3.localtunnel.com ...
I prefer it over other approaches, especially in instances where even for development work your application is required to be publicly accessible due to some remote services that your using, in which case you can programmatically instantiate localtunnel and do all the necessary configurations, without having to document it or go through the pain of performing it manually over and over again.
Are you running python manage.py runserver?
Try doing python manage.py runserver 192.168.1.2:80 (or whatever your IP is instead of 192.168.1.2).