I have a customer that sells a multi-tenant SaaS platform. I often have to run the thing locally, but there is some interaction with other websites that then redirect to the customer’s system. And these website won’t redirect to localhost of course. What’s more, the application running on my localhost is running on port 3000, instead of 443 (the default HTTPS port). Let’s see how we can fix this.
The hosts File
First, we need to tell our system that our URL (https://example.com) is actually hosted on localhost. Assuming you’re working on Windows, open the hosts file as administrator. You can find it in C:\Windows\System32\drivers\etc. Then add a line like this:
127.11.11.11 example.com
It doesn’t have to be 127.0.0.1.
When you request https://example.com now, your local system will want to respond. Anything listening on port 443 will now respond. My local application was listening on port 3000, so I didn’t get a response.
The netsh Tool
Open a command prompt as administrator and tell your system to forward requests on port 443 to port 3000. At least, for the correct IP address:
netsh interface portproxy add v4tov4 listenport=443 listenaddress=127.11.11.11 connectport=3000 connectaddress=127.0.0.1
So all requests that enter your machine for 127.11.11.11:443 are sent to 127.0.0.1:3000, which is where my local application was running.
Cleanup
Of course, once you’re done testing, you want to clean everything up. The hosts file is easy: just remove the line.
For the netsh tool, run the following command:
netsh interface portproxy delete v4tov4 listenport=443 listenaddress=127.11.11.11
And now everything’s cleaned up.
So that’s how you can intercept calls and route them to your own application, regardless of which port it is listening to.
2 Responses
Hey Peter, hello actually I am interning at a reputed company in India and I am tasked with building a website that receives pdf from the user and converts to flipbook using HTML, CSS and JS (which I have successfully made). The problem here is that they have asked me to generate a unique URL corresponding to each flipbook. I am even done with that, but when I put that URL in a new tab’s address browser the site opens up but without the flipbook. Is it because I am using local server and have not hosted the website yet? I don’t know the real problem , can you help me in this matter?
Hi Aditya, without more specific knowledge, this is a difficult one to solve. My post was about public websites that need to redirect to a website you’re running locally on your PC. From what I can distill, I think your issue is not that. Rather, it’s an issue in your application. I’d suggest you contact your intern coach/mentor on this. Good luck!