I managed to find a solution.
Before you attempt this, setup port forwarding for Chrome mobile debugging and keep track of the ports. Let's call them:
- Port 1: the listening port on the device e.g. 6040
- Port 2: the listening port on the local machine e.g. 8090
Steps:
- Install Node.JS (if you don't have it)
- Create a file called
proxy.js
in a directory of your choice
- Copy the contents of the code from this gist and paste into
proxy.js
- Run the following command in the terminal from said directory:
PORT_LISTEN=8090 PORT_TARGET=80 HOST_TARGET="my-local-server" HOST_ORIGIN="my-local-server" node proxy.js
What's happening is as follows:
- Chrome has already setup a port-forwarding setup from your device to
localhost:8090
- By running the code above, you have created a proxy server to listen on port 8090 and forward to your local server at port 80. The
HOST_ORIGIN
indicates to the web server who the request is for i.e. my-local-server
localhost:6040 --> localhost:8090 --> my-local-server:80
On your device, you should now be able to visit http://localhost:6040
and see your local server/domain site.