Access local nodejs server from google spreadsheets - node.js

Currently, I have a google app script backend connected to a spreadsheet.
This app script backend does REST api calls to my website hosted at https://example.com/example and everything works fine.
The issue is, to do testing I have to make changes to local code, deploy and only then test if everything is working in order or not at the remote server "example.com"
When I try and change the site to https://localhost/example (with nodejs server running locally) it fails with a bad hostname/dns server not found issue.
How can I work with spreadsheets/app script so that i can work with my local nodejs server ? Is it possible ?

use ngrok , Checkout the npm package here https://www.npmjs.com/package/ngrok, or
you can directly download and use it, check here.
ngrok secure introspectable tunnels to localhost webhook development
tool and debugging tool.
Edit:
In my case, I had to
Download ngrok on my windows machine via the ngrok website
Connect account:ngrok authtoken <tokenid>
Run ngrok on my machine like this: ngrok http https://localhost:port
Connect via the public ip at https://<somename>.ngrok.io, where "somename" is a unique id which is created by ngrok.

Related

HTTP requests between two docker services works fine but I don't know why [duplicate]

I have a ReactJS project with its own Dockerfile, exposing port 3000:3000.
I also have a PHP project with its own Dockerfile, exposing port 80:80. The PHP app also has containers for MySQL, Redis and Nginx
For the PHP app, I have a docker-compose file that creates a network (my-net) for PHP, Nginx, MySQL and Redis to communicate on. However, I now want the ReactJS (which is in a separate project) to be able to communicate with the PHP app.
I added a docker-compose file to the React project, and added it to the network from the PHP project my-net and declared it as external so that it doesn't try to create it.
This seems to work: From the ReactJS container, I can ping app (the name of my backend service) and it works properly. However, from the ReactJS code, if I use something like axios to try and hit the backend API, it can't resolve app or http://app or any variation. It can however access the underlying IP address if I substitute that into in axios.
So there seems to be some issue with the hostname resolution, and presumably this is on the axios / JavaScript end. is there something I'm missing or a reason this isn't working?
When the JavaScript runs in a browser (outside of Docker) you can not use app because that is only available inside the Docker network (via the embedded DNS server).
To access your PHP server from outside use localhost and the exposed port (80) instead.

Local server http communication and angular browser rendering

I think I'm doing something completely the wrong way.
I have an Nodejs server running that read in a DB and serve with express some data via http locally (it has to only be accessed locally). It sends the data on localhost on some port (8080 for example). Then I have an angular app on the server that get these datas from an http request on localhost:8080 and display them. The angular app runs locally on localhost:4200.
I was building the entire stuff on my computer and that was working perfectly (I have no problem with CORS). Then I deployed it on a server, and I accessed it via ssh port forwarding. Basically I forward localhost:4200 on the server via ssh on my local computer on localhost:8090.
And my problem is that, when loading and executing the angular app in my browser via port redirection, it's doing a get request to localhost:8080. So it's trying to communicate with the localhost it's running on, which is the client itself.
If you understood my spaghetti situation, there is actually a dirty solution : redirect localhost:8080 on the server to localhost:8080 on the client.
Is there any way to do the get request server side and not in the client's browser so that localhost correspond to the server? Is there a better way to do what I'm trying to do?
I can sum up by : How can you access another local service on localhost on the server with angular app since it executes in the client browser and localhost will refer to client localhost.
Try to use any web server (such as nginx or apache2 or etc.) in your server and make use of proxy and reverse proxy with your node application, it will work
angular2-router-and-express-integration

How to connect node app to node api with Nginx

I built a Node app using this tutorial. Then I built a Node API using this tutorial. The app uses the app on port 4000 to connect to the API which then connects to a mongodb to store the info on the server.
This setup works great on my local machine, but I'm trying to deploy it on a digital ocean droplet. I have Nginx setup to listen to port 8080 for the main app. I'm able to navigate to the app. But when I try to register a user and submit the data to the API I get the following error in my browser OPTIONS http://localhost:4000/users/register net::ERR_CONNECTION_REFUSED.
I suspect I have to specify something in the Nginx config files. Or would it be a ufw issue? Any help would be much appreciated.
The error is very clear. The application try to fetch on localhost:4000, so you expect any visitor of your web app to have the API launched on their own computer.
Change your code to point to the correct host and port of you server.
Then, as you guess it, you will have to create a little Nginx configuration to tell him what to proxy to the APP and what to proxy to the API.

MEAN Stack - Angular can only Communicate through the domain name

I have setup a Mean stack on a Digital Ocean Droplet based on UBUNTU 18.
I am using Angular6 on nginx port 80, nodejs on port 3333 which I run on the same machine. I have also enabled CORS on nodejs. The angular application gets build as prod and copied to the server. I have enabled as described on digital ocean the private ip and i can successfully curl the api (nodejs) using localhost, the internal IP and 127.0.0.1
Now the problem: When I am calling the API from the angular6 anything but the domain name is giving me an Error -> Connection Refused, Unknown Error! Locally on my development PC everything is working as It should! I thought it might be a cors issue but I am able to access via IP the remote API from my development machine without any issues. What am I missing? I find it very odd to be able to access it through the domain name and not via the internal IP...
Note that on the development PC angular is running as ng serve... the only difference is that the application is build as prod before uploading it to the remote server.
Angular cant access the private ip because the angular code runs off your browser and not the server. So unless your running the browser right on the server via vnc or something, your local machine cant access the private network (and thus the private ip).
Digital ocean probably recommend you set up a private ip so that you can put your database in the private network so its firewalled off.
Anyhoo, use the FQDN or the public ip in your angular code.

Accessing express server from different geo location

So me and my friend are working on a MERN Stack app, I am working on backend(Node.js) and he is working on Frontend(React.js). We are from different places, My Question is how he can access my localhost server, So as to hit on my APIs.
Provide me with all the possible solutions so that my APIs are always available to him.
You need something like this: https://ngrok.com/
Ngrok is a tool that allows you to securely open a tunnel to your local machine while ngrok is running.
Its has a free plan, or you can pay for extra features like setting a custom domain
You can install ngrok as a global npm package with:
npm i -g ngrok
And then once your server is running locally, you can start ngrok in another terminal pane/window/session and point it to the port your server is running on, below we assume the port is ‘3000’:
ngrok http 3000
This will open the tunnel, and print a url you can send to your friend to make requests against. Requests made to the url will be proxied to your localhost at the specified port. It supports HTTPS as well.

Resources