How to tunnel localhost to the public Internet
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
In this article, I’m going to show you how you can tunnel your localhost environment to a public Internet address that can be accessed by other services you are using for testing.
Why tunnel localhost to a public Internet address?
If you are optimizing the front-end of a given web application and want to see how effective your changes are, you can use a tool like GTMetrix or Pingdom Website Testing.
The problem is that those tools can access only a public Internet address, not your localhost environment. And, while you can deploy your temporary changes to a QA environment that’s publicly accessible, there’s a much simpler way to achieve this goal.
Or, while developing RevoGain, the most awesome Revolut trading grain calculator, I had to test the FastSpring payment integration. The payment callbacks need a public Internet address that FastSpring calls after making a purchase. To test the integration, you’d need to expose your localhost environment to a public Internet address so that FastSpring can call your own environment.
And the solution to this problem is to open a networking tunnel between localhost and some public Internet address all those services can access.
Networking tunnel
In networking, a tunnel allows you to transport packets from a private network to a public network. For instance, tunneling is used with VPN (virtual private networks) to secure network connections.
The Linux ssh
port forwarding is also using another example of a networking tunnel, which allows you to transport packets securely from your localhost environment to a public network.
LocalXpose
While there are many ways to create a networking tunnel, my favorite tool is LocalXpose because I can choose the region where to open the tunnel. This has allowed me to check various use cases when I integrated the FastSpring payment system.
@echo off loclx account login loclx tunnel http --https-redirect
To open an HTTP or HTTPS tunnel, all I have to do is run the following command:
> tunnel ┃ Tunnels ┃ Running tunnels on current instance Type Region From To Status http us 6mxq9u9azj.loclx.io http://127.0.0.1:8080 running
That’s it!
Now, localhost:8080
is available at the 6mxq9u9azj.loclx.io
address.
Or, if you want to choose a certain region, you can use the --region
flag, like this:
loclx tunnel http --https-redirect --region eu
And, this will open a tunnel in the European Union, not the United STates, which is the default region.
Testing time
To test how well the front-end performs, I can now use GTMetrix to analyze the Spring Boot server running on my localhost environment:
Awesome, right?
If you enjoyed this article, I bet you are going to love my Book and Video Courses as well.
Conclusion
Exposing your localhost environment to a public Internet address is a very handy feature when testing a web application.
LocalXpose is a very simple tool that allows you to create a networking tunnel between your private web server and a public Internet address.
Another alternative to LocalXpose is ngrok, which also allows you to tunnel localhost to a public IP address.
Note that I may receive a commission when you click on our links to make a purchase. This, however, has no bearing on my opinions related to LocalXpose.
As stated by the blog ethics policy, I do my best to keep things fair. All my articles are written independently and reflect entirely my opinions and conclusions.
