I've been working on a react app and I wanted to get hot re-loading going so I set up a webpack dev server. It's working great. It runs on localhost:8080 and the hot re-loading works perfectly.
Great, now I just need to set up a proxy to route requests from 8080 to my flask server running on 5000 right?
Cool so I added a proxy field to my webpack.config.js
27 devServer: {
28 static: './static/dist',
29 proxy: {
30 '/': 'http://localhost:5000',
31 secure:false,
32 }
33 },
But when I re-run npm run start
"start": "webpack serve --open --mode=development"
I get all of these connection refused errors. My flask is up and running fine and I can query the api routes directly and have data be returned.
[webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/all_users to http://localhost:5000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
I followed the URL and the only advice there was that this error usually occurs when the external system is down. Since mine isn't, I'm pretty confused.
Any help would be greatly appreciated.
I have no idea why but changing 'http://localhost:5000' to 'http://127.0.0.1:5000' solved my problem.
If anyone knows I'd still be curious why this fixed it. I can go to 'http://localhost:5000' in my browser and query my backend just fine.
Related
Trying to access django server on localhost from my react native app. All I get is Network Error, which doesn't say much. Tried changing info.plist file as suggested in other answers on stack, tried changing firewall settings and so on.
The thing that worked and solved all my problems was changing the url on axios to my local ip and running django server with command: python manage.py runserver 0.0.0.0 which to my understanding will accept any connection to the server.
I am currently running into an issue with one of my projects that will be running in Docker on my Ubuntu Server with a NGINX docker container to manage the reverse proxy for the Django Project. My issue I am running into is I already have previous Django projects running on that particular Ubuntu server so port 80 is already being used by a NGINX block running on the actual server.
Is there a workaround to running my Docker NGINX as well as the Ubuntu NGINX and have my docker image run as a "add on" site because the Django sites hosted there are clients websites, so I would prefer to not interfere with them if I dont have to.
My project needs HTTPS because it is serving data to a React-Native app running on Android APK 28 which for some reason has a security rule that blocks non HTTPS connections from happening in the app. If anyone else has run into an issue like this I would gladly appreciate the advice on how to tackle this issue.
I have tried running NGINX in Docker with port 81 instead of port 80 and that works perfectly, but I dont think there is a way to make a secure connection to port 81 is there?
Thanks in advance.
You can't just mess with default HTTP ports for endpoints - user browsers use 80 and 443 by default. If you change those, your users would have to connect to your.server.com:81 or something similar. Nobody would do that for a public server, but this can be an option for a private one.
I think a reasonable way out of this will be to use host's NGINX to proxy requests into Docker's NGINX (if there is sense in keeping it at all). You can handle HTTPS termination on host's NGINX and pass plain HTTP into Docker's one.
Another adequate option is to use another server, so that everything works with no dirty hacking involved.
I have a google appengine project running in localhost. Everything works fine until i go to the 'login' page. When i go there i get the following error:
This site can’t provide a secure connection 127.0.0.1 sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
the appengine command i use to run the project is dev_appserver.py" --host 127.0.0.1 . This is run pycharm. This only occurs in the 'login' endpoint and no other endpoint.
The console error i get is:
default: "GET /signin HTTP/1.1" 301 -
to connect over HTTPS you need a valid SSL certificate on your server here is you local server as I understand from the message. you can get a certificate for your local server but I don't think it's worth the trouble while working locally. On the other hand when you deploy to Google App Engine, you get SSL certificate automatically and it's managed by Google, that's why your code works without any problem in the deployment.
So, I have recently started using CF and am using the same to publish a nodejs app to my cf space.
As suggested in the CF wiki, I have used the nodejs_buildpack to
build my app so that can be run via CF PaaS.
Although I don't need this if I push my own cached
node_modules dependency folder in the CF Space , please correct me if I am wrong ?
Following screenshots represent the output of cf push ,
Output of : CF logs STARS --recent
manifest.yml
---
applications:
- name: STARS
buildpack: nodejs_buildpack
memory: 256m
disk_quota: 512MB
instances: 1
command: npm run build
I don't understand why 8080 fails as this works like charm on my machine. i.e. localhost:8080
I do set the express in the following way though,
app.set('port', process.env.PORT || 8080);
// set up listening
app.listen(port, function (err) {
if (err) {
console.log(err)
} else {
opn('http://localhost:' + app.get('port'))
}
})
--Update--
As suggested by #K.AJ in the answer below I have tried to increase the memory limit in my manifest from 256 to 512 and you know what it started working. :)
But its a little strange that the allocation 179.4M in memory and 206.1M on disk is present. Looks like the addition of these two is considered in the deployment process.
My updated configuration is ,
app.set('port', process.env.PORT || 8080);
In the above statement, the port is 8080, only when running locally.
On cloud platforms like PCF, you have no control on which port an app will be running.
If you look closely to the error message, your app is crashing due to out of memory error. The 256MB memory is not enough for it. Try setting it to 1GB first, get it working and then optimize it.
Assuming, you have successfully deployed your app, run cf apps. It should list you the deployed apps along with the route.
Copy the route url for your app and run it in browser. You should be able to see your app, provided your app instance is healthy and in running state.
Please go through documentation on PCF
https://docs.pivotal.io
https://docs.pivotal.io/pivotalcf/2-3/devguide/index.html
https://docs.pivotal.io/pivotalcf/2-3/devguide/index.html#deploy
I have a Django site that uses Gunicorn and Nginx. Occasionally, I'll have a problem that I need to debug. In the past, I would shut down Gunicorn and Nginx, go to my Django project directory and start the Django development server ("python ./manage.py runserver 0:8000"), and then restart Nginx. I could then insert set_trace() commands and do my debugging. When I fixed the problem I'd shut down Nginx and then restart Gunicorn and Nginx. I'm pretty sure this was working.
Recently, though, I've begun having problems. What happens now is that when I've stopped at a breakpoint, after a couple of minutes the web page that I've stopped on will change and display "404 Not Found" and if I take another step in the debugger, I'll see this error:
- Broken pipe from ('127.0.0.1', 43742)
This happens on my development, staging, and production servers which I'm accessing via their domain names, e.g. "web01.example.com" (not really example).
What is the correct way to debug my Django application on my remote servers?
Thanks.
I figured out the problem. First I observed that when I stopped at a breakpoint, the page always timed out after exactly one minute which suggested that the Nginx connection to the web server was timing out if the web server took more than 60 seconds to respond. I then found an Nginx proxy_read_timeout directive which defines this timeout. Then it was merely a matter of changing the length of the timeout in my Nginx config file:
# /etc/nginx/sites-enabled/example.conf
http {
server {
...
location #django {
...
# Set timeout to 1 hour
proxy_read_timeout 3600s;
...
}
...
}
}
Once you've made this change you need to reload Nginx, not restart it, in order to this change to take effect. Then you start Django as I indicated above and you can now debug your Django application without it timing out. Just be sure to remove the timeout setting when you're done debugging, reload Nginx again, and restart Gunicorn.