I am working on an automation project
I have a local server inside adobe cep. It's a node js/express server.
I want to be able to send an API request to that server from a cloud server.
How can I connect my local server to the web so I can run an HTTPS request that will arrive at my local server?
Thank you very much for helping with this
I didn't really know where to start with this, searched online but didn't get any results yet
This is a two steps configuration, you want to call a local server from the cloud, so:
first of all you need to know your IP (if dynamic it may change)
or you want to use a service like dynDNS so you can associate an ip (192.1.2.3) or an URL (http://myLocalserver) that is callable from the web.
Additionally, you need to setup the port forwarding in your rooter configuration so you can connect your local server (localhost:4200 for instance) to http://myLocalserver:4200
Related
I have a neo4j desktop (1.4.3) database on my Windows PC. in an html code, I am connectecting to the DB using
const driver = neo4j.driver("bolt://IP_ADDRESS:7687", neo4j.auth.basic("neo4j", "PASSWORD"));
After that I query the DB and display the results on the web page (I use leafletjs maps, but this is not the issue)
var session = driver.session();
session
.run(`MATCH....etc.... return ....
`)
.subscribe({
...... etc
Everything is fine so far. I run the page on my PC or from another PC in my home network, everything is fine. The setting of neo4j is (dbms.default_listen_address=0.0.0.0) no issues there.
The question is how do I expose this page to the colleagues outside my network?
Using noip.com, I got a temporary domain mapped to my external IP.
I also configured the router to forward port 80.
But when the page Javascript gets loaded on an external client, it tries to connect to neo4j on that client. When I put the external IP addtess in "const driver ..." the connection does not work.
How do I make the connection to the DB from my server, but the queries to the DB come from the client who loaded the Javascript?
Edit: Forgot to mention that I am also using Apache Web Server (Xampp) to serve the page to remote users.
A simple architecture that does what you want, plus mitigates the risk of opening up your database to everyone uses a HTTP server + API that are accessible via your noip provider.
Your public facing frontend (HTML + JavaScript (for making API calls etc)) makes the HTTP(s) calls to your publicly accessible API (for example a nodejs server) to make the database calls. Cypher/a direct database connection to neo has no place in your users' browsers.
You can also use a starter like the GRANDstack.
Right now I am using an OpenWeatherMap API key in my client side javascript for a simple weather app (Node/Express). I know this is not ideal outside of development, so I did npm install dotenv.
On the server side, I can get and set the env variables just fine in Node. I can see them when I console.log out.
How do I call the API key in my javascript on the client-side? For example, currently my weather app has its simple logic in a file called weather.js and the HTML uses weather.js.
Ideally I would just like to call my api like http://api.openweathermap.org/data/2.5/forecast/daily?lat=${lat}&lon=${lon}&units=metric&appid=${process.env.WEATHER_API_KEY}
I know the .envs are on server side and you have to do stuff to make it work client side. New Node developer here who has read too much that I think I am confused between requireJS, Browserify, modules, .env, etc...
You don't want your API keys (or other secrets) to be public. Using them in the front-end would make them visible when inspecting the page and in the network requests log. You need to store and use your secrets server-side.
Create a route on your backend (which you protect from being used by other domains using CORS) which calls the weather API (using the token stored in .env on your server) and sends back the data.
Then have your frontend hit that route.
You will have to request the API Key from the server.
This can be done easily by making a simple route in your backend that will return the key as a response.
If you don't want to expose your API Key (I recommend you to not expose it), what you can do is create a route in your backend that will make a call to the WeatherAPI using your API key, and the client will send HTTPS request to your backend, which will then create another HTTPS request to the WeatherAPI and send the response back to the client.
You don't want to expose your API keys to outside world. What you can do is to create backend route (/api/keys) make it protected with CORS and call it from front-end.
Using Express when we use app.listen(port) , the app location is localhost:port/
In local machine I completely understand how we can access to this address as we use a local browser running on same machine . Even other clients running on same network can access the server.
As per my knowledge localhost or 127.0.0.1 IP can be accessed on same or other machines in same network.
But if we deploy to cloud like Heroku without adding IP option like app.listen(port, IP_ADDRESS) instead we use app.listen(port), the only thing that varies is PORT number(process.env.PORT) but IP is still localhost. So how can clients from other networks access the server?
You can use port forwarding on your router to forward router_ip:port to local_ip:port allowing you to access it externaly
Just because you are connecting to your local instance via localhost doesn't mean it is not also exposed via IP. Localhost basically says don't resolve any IP, just loop back to this computer, but your node server will still be deployed to an actual IP address. Try looking up your computer's IP address and connecting to your node server through that instead of localhost, and you'll find you're still able to communicate with the server.
When deploying to a cloud service, or any other hosting service, you'll be given an IP address associated with that instance which is what will be used for resolving. Heroku in particular will blackbox a lot of the domain-space and port-forwarding process for you.
I currently own a website, which will be used for global access and a database. I am also building devices that run a local node.js server, that forms a connection to this website.
So I guess this would be a reverse websocket? I don't own the webserver, it's hosted, so I'd assume I would use php.
I'm needing a 2 way connection that can push or request updates from both ends... Maybe websockets isn't the answer in this case?
so this is my problem:
I have a node server with a game i'm creating. the node server is listening in a ip mask that is given to him in network, like 192.168.x.x (isn't always the same).
The game 'frontend' is a web page, in a domain (like paperplane.io) that points to my dropbox project and makes it accessible.
How can I make my game frontend, the client, know behind what mask is node server listning, in that network, so it can communicate with it with no specific configuration.
Synthesizing: start node server in local network. every device in that network can access it via web url. plug & play.
thaks
Ok, so i solved my problem by having my node server sending updates to a mysql database with something like: I'm XPTO and I'm at 192.169.X.XX.
so, when i access my application i tell her what i'm looking for (i always know) like this:
XPTO.application.com
by the subdomain i check the database for key:value and get my nodejs ip mask in network.