[local IP]:[PORT] redirects to public website (Flask, server configuration, local environment) - flask

I want to debug a flask app on mobiles.
My application configuration allows to expose the app to the network:
application.run(host= '0.0.0.0',port=5000,threaded=True)
However, if I load mylocalIP:5000, it redirects to www.example.com, where the production site is hosted, and cannot figure out where it is written to resolve the redirect.
So I cannot see my local environment but in my local machine, and cannot debug the app on other machines - like mobile phones.
Where should I look to solve the problem ?
I must have changed configuration on my machine somewhere, I don't think it is related to flask.
Note: as alternative , I tried use my local host alias:
I'm using a mac, System Preferences > Sharing > Internet Sharing is enabled, other computers in local networks can access my local env at myLocal.local host, but still access to myLocal.local:5000 is forbidden for other machines but my computer.

You can do one thing, install Fiddler app and configure the reverse proxy on your mobile phone. This tutorial will help you to configure fiddler in android applications.
After configuring the reverse proxy, run the flask application on localhost or machine IP and you can access your machine IP on your mobile. Fiddler would also help you to intercept all the calls made to your application. If you don't want to inspect via fiddler you can directly put your mobile on same network of application.

Related

Do we have to host our Django site for our Flutter App backend?

Suppose I am creating a todo list app in Flutter. I have used Django to connect flutter's backend with the local host database. Now my API's(Django Rest Framework) are working fine if the is on local machine. But what if I deploy my Flutter app to Play Store? Then I need to host my Django site as well or it can be upon the local machine?
Development
If you are in development the local machine is enough. For connecting the Flutter app to the Django development server follow the steps below.
connect your local server and mobile device to the same network (for example, a common wi-fi)
Get the IP address of the local machine. In Linux, the command is ifconfig,
and in Windows, it is ipconfig. It will be something like 192.168.1.8
Run the Django server with the following command in the terminal, providing your IP address you got in step 2:
python manage.py runserver 192.168.1.8:8000
To test, try access the IP address (with port) via. a browser on the phone. If it loads, the connection is correctly set up
Now you can use this address in your request in the HTTP request in Flutter
Production
If you are deploying the app in production, you can host a server (AWS/EC2, for example). You will get the IP address somewhere in the console. Deploy the code to the server and run the code there. Replace the local IP address in app with the IP address of the server. You can also use packages like Environ for this.

Configure my local flask server to be available to other devices under same wifi network

From most of the resources, I gathered-
If I declare 0.0.0.0 as host and 5000 as port explicitly,other devices under my wifi network should access it, but when I type http://0.0.0.0:5000/ from another machine(my windows laptop), it didn't work.
port 5000 needs to be open. If not then I should open that.
That didn't work for me either.
Perhaps debug=True parameter should be removed from Flask's run() method as dev server shouldn't be publicly available. Still no luck!
What else could be the problem as the following isn't working for me-
app.run(host='0.0.0.0', port=5000)
I know, this question has been asked couple of times, but none of the suggestions worked for me. So, please help me access my flask Restful API through other devices as I want to test the service having a web application and mobile application as clients.
The Flask dev server should not be used in production as it is not designed to be efficient and secure. Flask Deployment
To make the flask dev server visible on LAN/WLAN add the host parameter to run on machine's IP Address
app.run(host='0.0.0.0', port=5000)
To Access the web server use private ip address(LAN/WLAN) of the machine running the flask server 192.168.1.23:5000

Hosting Back end Application with API on EC2 instance

I'm quite new to AWS and I have been starting to work with EC2 instances. I have a web application that has a frontend and backend separately. So first I hosted the backend application on EC2 instance and it is a Symfony framework based REST API Application. So I have installed all dependencies and now the application is running. But to check the application I ran some API calls to the application using postman and seems application is not working as intended. I get following response from Postman. I have also provided security group configurations properly.
When I start sysmfony app it says [OK] Server listening on http://127.0.0.1:8000.
Can't figure out why this is happening. Can someone help me here?
You are running your application trough CLI (Symfony web server bundle) , by default this will bind to 127.0.0.1 which can't be accessed from outside. To fix this, you must bind to your server's public IP/hostname and port:
php bin/console server:start 192.168.1.1:8000 # replace with your ip
You can also bind to all your IP addresses using 0.0.0.0
But keep in mind, you should not use built in server for production, it's slow and less secure. Use a real web server instead, like Apache or Nginx.

C++ console http api app deployed on Windows Server 2012 is not accessible externally

I am trying to deploy a simple HTTP API app on an Window Server 2012 and it's not working. The app is accessible internally (I can ping it within the server) but NOT externally. What do I need to do make the API server accessible via network? I disabled the firewall so it's not a firewall issue. I would usually use Linux, but I don't have a choice but use Windows this case. Please help!
I solved it by installing IIS and use it as a reverse proxy. So when a http request comes in from the internet, IIS it takes it and forwards it to my web app.. I am not sure this is the right way or not, but if it is, then it's pretty stupid as my web app should be accessible directly which would have been the case if I were using Linux.

Facebook Debugger unable to test localhost

I am building a Facebook app using Django. So, for development, I connected the app to localhost. My app is loading on canvas and working fine but the Facebook debugger is unable to test it correctly when I give localhost address as input.
These are the requests I tried in debugger
http://localhost
https://localhost/
http://127.0.0.1/
localhost
etc
Almost for all possible combinations.. It showed me
Error Parsing URL: Error parsing input URL, no data was scraped.
When I deployed the same code on heroku and tried.. It was working!
So,
Can't I debug the project on localhost? What's the point in working on it then??
If I can work, how should I fix it?
Can't I debug the project on localhost? What's the point in working on it then??
You can debug your code etc. on localhost – but of course you can’t have Facebook’s debug tool reach a site on your localhost, because Facebook (and everyone else on the web) does have no idea what machine your localhost actually is. (Absolute bascis, dude!)
If I can work, how should I fix it?
You have to make your web server accessible from the “outside”, over the internet.
Set up your test server so that it accepts requests from outside IPs, and get a DynDNS address (basically something that can be resolved by third parties like Facebook over the DNS).
You can access Facebook apps locally but you need to fake the domain of your local computer. You can do this by adding
127.0.0.1 mysite.test.example.com
to /etc/hosts. You should update mysite.test.example.com to your domain. Your Facebook app needs to be configured for that domain. You can then use the Facebook app locally and debug your project.
The alternative is to setup up a web server and use its domain for testing purposes (but this is not ideal because you'll need to commit and build the code before you can see your changes).