I'm trying to do some home automation with my Raspberry Pi.
Right now I've set up a Node+Express API server (address http://192.168.100.100:3000, local folder ~/api), used to send the signal to a Air Conditioner and get the info from it.
Aside I've built a webapp with Vuejs to manage the AC, and setup a Nginx server to access the webapp (address: http://192.168.100.100, local folder ~/controller/dist).
Everything works perfectly on the local network, but I want to access to everything remotely. So I've forwarded the port 80, and I can access the webapp over the internet, but it doesn't work, because it can't access the API server.
Is it normal, and I have to forward also the port 3000, or is there a way to tell the app to look for the API on the localhost?
Both should work in the local network because everybody knows who's who. If the communication is server to server, both should work too because it's the same scenario. But if client perform Ajax to communicate to server, you should forward port 3000 too. Because the request is out of the local context (if you are out of your network).
server to server: localhost -> localhost
client(browser) to server: internet -> localhost
You could avoid the forward if server(local) perform a request to a client(remote).
You can forward port 3000, and it should work.
Another option is to use ngrok. It allows you to open a tunnel (regardless of your firewall settings) straight to your API. All you have to do it register a free account and you will be able to have a single tunnel running indefinitely. Only drawback is that you need to use their shortUrl (Like https://asdasd12.ngrok.io which changes every time you restart. You can pay to get rid of that, and get a permanent subdomain(Like https://myniceapi.ngrok.io)
Related
I deployed a web application which require to send request and get response from a local ip(ie. 192.168.0.123), which is actually a payment terminal.
It seems that this violate the entire https purposes, however I have no control on the payment terminal and it's address due to 3rd parties API.
Are there any workaround to handle localhost/ local ip ith https request?
If you can install additional software on the payment terminal, then you could install another HTTP server that acts as a reverse proxy and listens on HTTPS.
You then make your requests to https://192.168.0.123 and your reverse proxy forwards them to its http://localhost.
Nginx is a popular server for this purpose.
If you can't install additional software then you should look at using an isolated network instead.
It doesn't really matter if communication over a local network isn't encrypted if you completely trust every device that is connected to it.
i wanna use node js on my webpage, which is hosted by a company. I saw that you can run a local server on node js, but does anyone know how i can link it to my existing domain example.com.
As mentioned I saw that you can use express for this, but i dont know my port neither how my server reacts to my js code.
any recommendations?
To be able to access your locally developed node project from your domain name from any computer connected to the internet you will need to do something like the following:
Point your domain's DNS records to your server
Log into your domain name provider and find the DNS settings section, then paste in your servers IP address. Once this is done, visiting your domain name in the browser will connect the domain to your server which you control. Under the hood the browser can now successfully ask the domain name server (keeps records of domains and associated IP addresses) for the IP address to query which corresponds to your domain name. But thats not quite enough yet!
Install a server application on your server
A server is just a normal computer with server software installed which enables incoming requests to receive a response in anyway you define in the configuration of the server software. nginx, apache and express are all types of server software.
At this point you need to see whether the server you are renting supports nodejs as a server, if not you should look elsewhere for a provider that does. (not hard to find)
Install software dependencies to get your express server up and running.
EG:
node, npm, express
I am trying to build an app to retrieve data from a local database, The structure of the app that I have a mobile app, server(on a hosting service), and local server(on my pc), I am trying to make the mobile app request data from the server via a normal HTTP request then the server request the data from the local server but the problem that I could not be able to connect with my local server I believe that I could not connect to my local server because my local server does not have a public IP, so I am trying to find a better way to achieve my idea.
I read something about Websocket but I don't know if it suitable for my idea beacuse it is Bi-directional connection and It most used for chatting app
I want to build the app with NodeJs, so what should I do to implement this idea, and thank you for the help.
Each server is on a different network the main server is on Heroku host and the local server is on my personal computer
Life would be a lot easier for you if you move your local server to Heroku where they can much more easily and securely talk to one another.
You can't connect from your Heroku server to the server on your private local network because it is behind a firewall in your home router. To allow such a connection, you have to configure a known public IP address for your home network (that won't change or use DDNS if it can change) and configure port forwarding in your firewall/router so incoming connections from the internet on a specific port can reach your local server. You will then have to harden your local server against random internet attacks since it will then be open to the internet.
One other possibility is that you could have your local server connect to your Heroku server (perhaps with a webSocket connection using some sort of secret credential). Since your Heroku server is already reachable from your home network, this would require less networking configuration change. Depending upon what you're trying to do between the two servers, you could either have the local server just make a regular http request to the Heroku server (either sending data or asking for data) or you could make a webSocket connection and then data can be sent either way of the webSocket connection.
Is there a way that I can make a GET request from an external server (like google apps script) to my local server?
For example, I would like to make a GET request on this url: http://localhost:3000/api/get_data
If I do that then I get DNS error. Replacing localhost with my ip address gives Bad Request
The "localhost" address is not accessible from the Internet, so you can't use it.
Having your IP instead of "localhost" may work, that depends on the firewall rules of your ISP and on your local machine.
The easy way to expose your local machine to internet is either by using SSH (if you have the remote machine that is accessible from Internet, for example, Amazon EC2 instance). You can use -R ssh switch for that, something like this ssh -R *:8181:localhost:3000 remote-machine and you can use "http://remote-machine:8181" to connect to your app.
See also The Black Magic Of SSH / SSH Can Do That?.
Another way is to use service like https://ngrok.com/ that will do the remote part for you.
since I am learning node.js I was wondering about something:
When I use node.js server to run a websocket, so that clients can connect (like on a website via javascript), it always listens public. Isn't that a security problem, that everyone in the world would be able to send data to the ip:port. They just have to connect to the server via the data that are written anyway within javascript and send / receive data?
I was thinking about a token, which would make sense in Java or Swift etc, but in javascript it can be seen anyway?!
TL;DR: yes, It's totally secure.
Every time the browser sends an HTTP request, there is a port waiting for the server's response. The difference between this to an open port is that an open port is open for everyone on the web. In an HTTP request or web socket, the port opens only to the server.