简体   繁体   中英

Develop Node.js / React application on a remote server, and access it locally

I would like to remotely work on (or develop) a React application, but still check the results in a local browser. Using npm , on the remote server, I launch

npm start

in order to start the application.

It returns

Server running at http://localhost:1234 

Then, locally, I can access to the application in my browser at the address machineIP:1234 where machineIP is the IP address of the remote host. This looks convenient, but I do not want to expose my application to the entire world.

I am actually very surprised that the port 1234 is suddenly open to anyone. Maybe this is a configuration of my remote server under Ubuntu 19.04.

I see two potential directions:

  1. Can I prevent the port 1234 to be opened to the outside? And then open an SSH tunnel from my local host to the remote host on the (now private) port 1234?
  2. I could restrict the access to the application with a password, but after every restart of the application (because it is being modified on the server), I might have to log in every time.

How would you proceed to privately check your application (in your local browser) while it is running (and being constantly restarted) on a remote server?

Firstly, you may want to check if there is a firewall running on that remote server. If there isn't, then ufw is probably a good option. Make sure to sudo ufw allow 22/tcp or sudo ufw allow OpenSSH before sudo ufw enable so you can still SSH into the server. You can also choose to allow connections to port 1234 from your own local IP using sudo ufw allow from localIP to any port 1234 , where localIP is the public IP address of your local machine. Then you can simply go to machineIP:1234 in your browser to view your application.

If you don't want to or can't open port 1234 to your own IP, but do still have SSH access, then you can also set up an SSH tunnel using ssh -L 1234:machineIP:1234 machineIP . Then you can view your application by going to localhost:1234 in your browser.

I work a lot with node and react and I a tool to solve this problem for me. it is self-hosted and free, it use ssh but helps you with a UI

https://github.com/vicjicaman/tunnel-tool

If you need any help let me know!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM