How does one connect to a digital-ocean server from a local React project? - node.js

Background
I am working on the front-end of a project using React. The backend is saved on digital ocean, something for which I am a complete novice at, however I have made attempts to read as much as possible. I would like to be able to connect and make calls to the server from my local React project while I'm developing and testing. All that I have been given is the login details to the digital ocean droplet. My problem is that I am not sure what url/endpoint to use to make these calls.
What I've Tried:
Making calls to the ip that was given to me for accessing the droplet. e.g.: "http://148.41.158.149:8080" - this is not the official ip, just an example. I found out that this is wrong.
Using root#projectname:~# nslookup localhost, I used the ip given which didn't work.
I did manage to download the backend from the server and I can make calls to "http://localhost:8080", however I would like to know how to make calls to the server.
From what I understand, I need to retrieve the url for the server from the actual account. Is there any way to get this from the droplet?

Related

How to create a HTTPS tunnel on my vps for my twitch bot event listen

I found an example on how to use the twitch EventSub webhooks(https://github.com/twitchdev/eventsub-webhooks-node-sample/blob/main/index.js) but i'm struggling with finding out how to setup it up without having to install ngrok or other apps on my PC since i have a vps where i host the bot. I understood the GET method but POST is a bit difficult for me.
Hope i explained it well enough for someone to understand.
Twitch EventSub at time of writing only offers a "Webhook transport"
So you should be able to set this up no problem on your VPS, since your VPS is web accessabile.
To test this locally on your PC yes you will need a proxy/tunnel such as NGROK to make your PC web accessable.
A "webhook transport" (to over simplfy) operates in the same way a login from on a Website does. You fill in the form and hit submit, and the form is POST'ed to the server.
Webhook's it's the same thing, except the data isn't POST'ed as a form but a JSON blob in the body.
So you can use anything capable of receiving a HTTP POST. There are just a few NodeJS examples like the one you have linked kicking about.
TLDR: unless you are testing, skip setting it up on your PC and start with setting it up on your VPS, as the VPS doesn't need a tunnel, apache/nginx are the SSL Terminator that passes to your Node script, if you use a node script link the linked exmaple in the OP

Need Node app to watch external website instead of localhost

I'm still new to Node, so what I'm asking may not work the way I'm wanting to, but, here is my dilemma.
I have a website which has an old data collector (which I did not write) collecting data. I wrote a Node app that mimics the old data collector so that it can be replaced. But now that it's ready for testing, how do I point the Node app towards the website and not localhost? The Node app is going to be hosted in a secure server.
When I would test in Postman I would test the functionality for, say, the 'id' endpoint by checking
localhost:3000/id
but now I want is when a user on the website goes to an address such as
www.myexample.com/id
The code in my Node app will run. And I may be wording this wrong, but basically if one of the endpoints is hit, I want Node to run the code for that endpoint.
The code for my endpoints is along these lines:
router.post('/id.json', function (req, res, next) {
//do the things
}
Is there a way to have Node work this way with an external website? I've checked, but haven't come across anything that would work for this particular issue. I'm using Express and I've tried changing my app.listen, to
app.listen('www.example.com')
but I'm getting errors from there, so I'm not sure if I'm not using proper syntax or if this simply isn't what app.listen was intended to do. Ultimately, what I'm wanting to do is have the Node app work the same way with the website as it would with localhost.
You can't take any site name by just "listening" to it with node app. When user in the Internet goes to www.myexample.com/id, the url is resolved into ip address and user's browser connects to a server (physical machine) that is running on that ip address. This server then accepts the connection and serves the website back to user. If you own www.myexample.com domain name and the server this domain name points to, you should go to the server, take down whatever is hosting your current website and run your node app there. Your node app doesn't even know which website address it's being hosted on, all it cares about is accepting incoming connections and returning data. Also mind the port - http and https work on ports 80 and 8080 respectively (which are omitted in the url) and your node app, based on your description, is running on 3000

Use Electron-App (displaying an online Website) as a secure proxy to the local network

I've build a Web-App that is displayed in an Electron-App with Nativefier. That already works great, but now i need to send requests from the website to the local network to talk with some local devices which are (with it's ip-address) configured in the Web-App.
I had the idea to use the Electron-App as a "proxy" to the local network by using a javascript callback from the Website to the Electron-App (don't know if this is possible, just an idea), which then makes the local request because it's running on a computer in the same network.
The reason for this post is that i need ideas/tips to secure this and prevent allowing to talk to other than the desired Web-App (available under a certain domain) by developing something protective like checking or validating the Server, validating the request by sending it's hash back to the server or other methods.
So my questions are: is it generally a good idea to do something like this or is this a huge security problem and have anyone any tips to secure the communication and only allowing the communication to in the web-app configured devices in the local network?

How to setup an API server with no domain name

I've been struggling to understand this because I don't quite know what to search for. Basically, I'm working on a simple node server that just works as an API that is to be consumed by a mobile application. I'm planning to deploy it to DigitalOcean but since I don't need a domain name because I don't have a website, how will I send the HTTP requests to the server? My guess is something related to the droplet's IP but that doesn't seem quite right.
Just send requests to IP address and port from your mobile app. like GET http://54.54.32.23:3000/user-newsfeeds/15

Connecting to Node.js server from a website?

So say, you have:
A VPS running a Node.js server
A web host & domain that's running a website say www.example.com
Is there a way you can have www.example.com connect to the Node.js server and retrieve data from it?
Because I just started messing around with node, and I've looked at over 10 tutorials and read a bunch of implementations of Node.js and in all of their examples they say connect to localhost:8080 or 127.0.0.1:8080. (That would mean my vps would have to host www.example.com (the client) & the node.js (the server) for me to use both??)
But I haven't come across any code/tutorials that allows me to run a JavaScript script to connect to the Node.js server and load in data dynamically from the page I'm at. Thanks.
Here's an example of code I'm looking at. http://tympanus.net/codrops/2012/10/11/real-time-geolocation-service-with-node-js/
Yes, you can use any URL to reach a nodeJs server.
Routing a request (to say www.example.com) to a nodeJs server has nothing to do with the nodeJs server. You have to make sure that the routing rules are in place, but that is completely separate to your server.
Update in response to you comment clarification:
Are you trying to make connections:
client -> example.com -> node.js?
If so, and example.com is a standard server, then yes, just make calls to node.js URL, that'll work fine
If you looking for the below flow
node.js
client/
\
example.com
And if you client is a browser, then you will have to deal with cross-domain issues as discussed here AJAX cross domain call

Resources