why does json-server only work on localhost server? - api

I have an app where I used json-server to create a quick backend for me to test. My app now works the way I want it to, but I realized that my app doesn't work on other laptops/phones because my json-server uses localhost. Can json-server work with custom URLs, or does it only work on localhost? Do I have to start over and use a different backend? If so, does anyone have suggestions for which backend I should use?

If you want to test your backend on a cellphone or another thing you need two things
First
Your server and your client, in this case the cellphone both of them needs to be connected on the same wifi aka Local network
Second
Yow backend instead of pointing to localhost you need to specify the ip of your computer
json-server --host 192.168.0.xx file.json --port 4000

Related

Is it possible to host a Minecraft server on GitHub Codespaces?

I downloaded the Fabric server jar file to a GitHub Codespace and am able to run the server without trouble. However, I am unable to determine the IP needed to connect to the server. Starting the server automatically forwards port 25565 and I make the port public. However, I can't figure out which IP to paste into Minecraft to connect to it. How do I figure out the IP of the server?
I found an answer thanks to inspiration from this question.
Steps:
Set up the fabric server jar as you normally would, but on the codespace. Start the server.
Split the terminal so one is running Java (server console) and the other is running bash.
Install ngrok via npm i ngrok --save-dev.
Once the server is finished setting up, run the command ./node_modules/.bin/ngrok tcp 25565.
Copy the ip shown under Forwarding (minus the tcp:// part and including the port). This should look something like 4.tcp.ngrok.io:17063.
You now have the ip of the serve!
Note: The free version of ngrok has URLs which change every time, as well as a limit, but for small-scale servers this shouldn't be an issue. You are also limited by the free codespace usage limit GitHub puts in place. However, you can easily get around this by creating a secondary account that you use codespaces on only for the server.

Can't connect to localhost after expo update

I use expo and my iphone for create react-native application locally. A few months ago all was good. I used my local ip address for connecting to my local backend server. But after update expo started generate url as exp://r2-asw...exp.direct:80. Now I always get a connection error. I even can use my api via browser using my ip and port.
If I choose LAN instead Tunnel there is an infinity loader and get an error "There was a problem running the requested app. The request timed out"
The problem was in mac Brandmauer

How to test api calls from flutter app to localhost service?

I'm trying to understand how to test http calls from my flutter app (which is running in an emulator) to my backend service, which is running in debug on my pc on https://localhost:8080.
I get that talking to https://localhost:8080 directly from flutter won't work because it means "emulator's localhost", so I'm talking to my pc local ip, but I got CERTIFICATE_VERIFY_FAILED because of course https://192.168.1.123:8080 doesn't have a signed cert.
What is the correct way to handle this situation?
You need to use the localhost of your host machine, not the localhost of your emulator. To do that you need to use 10.0.2.2 and then your port number, so in your case make http calls to https://10.0.2.2:8080. Internally Android reroutes calls to 10.0.2.2 to 127.0.0.1, which is the localhost ip on your dev machine.
How do you connect localhost in the Android emulator?
Some more info: https://developer.android.com/studio/run/emulator-networking.html

How to transfer localhost to open server

I am trying to follow this tutorial. To train the Mahout engine they mention to use the command:
http://localhost:8080/kornakapi/train?recommender=itembased
This works. However I want to open up the server so that I can run this remotely. The code is running on a server at a specified IP address, let's call it 999.999.9.999. When I try
http://999.999.9.999/kornakapi/train?recommender=itembased
I get a 404 error. Obviously the server isn't setup to accept incoming connections (though phpMyAdmin works remotely). How can I setup the server to allow an external connection in this manner?
You need to configure your gateway to accept incoming requests. Access your modem and search for a setting that allows one computer on your LAN to open up all its ports. You have to enter in the computer's local IP

Hosting site using xampp server from local network without port-forwarding

I want to make my site available world wide. Im using xampp server for hosting. I have no access to any kind of servers and modems. Situation is shown below:
My site server has local ip assigned by wifi router and it runs Windows 8.
Remember I have no access on any kind of servers and modems so port port-forwarding is impossible (out of my scope).
Its actually difficult, but not impossible.
One way, I would approach this is:
I would host a page on internet.
Then take request and store it in database.
One of my program will always be running from my computer.
Then check for request and curl the request to localhost. For this you may use Node.js (taking data from database using GET method and curl it to localhost).
This is the best I could think of. And I am working on it, when the code is ready I'll make it open source and notify you :)
But still, it's difficult, as you need to put user's request to sleep for 2 seconds and then transferring it.
Its slow, but may work out for you.
Disadvantages:
Program will be very slow and memory usage will be more.
Breaking may happen many times.
High bandwidth wastage
If not encrypted, MIM (Men in Middle) may possible.
Advantages:
Indirect method of hosting
Need not to worry about your code being lost.
I am looking forward for a better alternative and I would like to keep this question for bounty once again.
If you cannot open the necessary ports within your LAN you will require access to an external server. However, the external server does not need to host any code, e.g.
Create a Linux based ec2 instance using Amazon's free tier.
Install a package to redirect remote to local ports:
a. using socat:
Install socat using your distributions package manager
Connect via SSH: ssh -N -R 42500:127.0.0.1:80 -o ServerAliveInterval=60 ubuntu#xxx.xxx.xxx.xxx -N -R 8080:localhost:80 "socat TCP-LISTEN:8080,fork TCP:127.0.0.1:42500"
b. using a webserver and reverse proxy:
Install apache or nginx and any required reverse proxy modules and configure your VirtualHost to proxy requests to a local port, e.g. :8080 -> 127.0.0.1:42500
Connect via SSH: ssh -N -R 42500:127.0.0.1:80 -o ServerAliveInterval=60 ubuntu#xxx.xxx.xxx.xxx
Your machine is now reachable via the ec2 instance http://xxx.xxx.xxx.xxx:8080/.
I occasionally use this technique when debugging web service callbacks.
Update 17-02-2014
If you are a Windows user you will need to install a third-party tool to support ssh. Options include:
cygwin
git bash
PuTTY
PuTTY is the easiest choice if you are not familiar with *nix tools. To configure remote port forwarding in PuTTY expand the following setting: Connection -> SSH -> Tunnels. Given the previously described scenario, populate Source port as 42500, Desination as 127.0.0.1:80 and tick the Remote option. (You may also need to add the path to a PuTTY compatible private key in the Connection -> SSH -> Auth tab depending on your server configuration.
To test you have successfully forwarded a port, execute the command netstat -lnt on your server. You will see output similar to:
tcp 0 0 127.0.0.1:42500 0.0.0.0:* LISTEN
Finally you can test with curl http://127.0.0.1:42500. You will see the output of your own machines web root running on port 80.
if you don't have a public IP address and cannot use port forwarding it is impossible to host the site
As people have said you need a public IP address. However, even if you did you should not use xampp as a public server, as it is designed for development and therefore has some security settings disabled.
I would recommend buying some shared web hosting, and uploading it to that. (you can get cheap hosting if you google 'shared web hosting', plus free .tk domains are avaliable: http://www.dot.tk/)
Do your company has any vpn network?
If it does and you have access to the vpn network, you can include your server to the vpn network and your guest will only need to login to your company vpn network then access your site like in a local network without using port forwarding. And since your data is very confidential, I assume that using vpn will also help to increase the security of your data.
Please correct me if I'm wrong.
Thank You.
What you are asking is not possible without port forwarding.
Lets break it into steps.
To host your site locally you will need a IP that is static so that
users can access it specifically.
You will need a domain so that it can be converted into user friendly name.
A 24x7 Internet Connection is must! You added a Wifi Router in your Diagram and most of today's router are capable of port forwarding.
What i will do in your scenario is:
Instead of using XAMP, i will install WAMP because i am more familiar with it and easy to configure.(totally personal preference)
Then i would set my server "ONLINE".(Google how to set WAMP server online)
Forward port "80" from router settings to my local computer ip address.(mostly it is tagged as "Virtual Server","Firewall","Port Forwarding",etc vary router to router in settings)
Suppose you have a local ip "192.168.1.3" and global/router IP "254.232.123.232" then you would redirect all the HTTP request done towards router to your local IP.
[[[[254.232.123.232]]]] --+ :80 +-- --------->192.168.1.3
That is good for now, but then you will need to tackle dynamic IP problem of router. But don't worry, thanks to some free sites that will be easy!
Go to no-ip.org -> Setup Account -> and create a entry, just a subdomain for now to test whether everything is working fine.(subdomain like mysite.no-ip.org, later purchase a real Domain)
Input your IP address there(Router IP) and download its application which will automatically update their server if your local IP changes.
Wait for some minutes and Voila! Your site is live.