Search code examples
reactjstypescriptsslwindows-subsystem-for-linux

WSL and devcert react page problem with local SSL


I got a react service project that due to a specific setup it runs on port 443 on development mode. It uses a dev-proxy that connects the local instance to a staging istance. The usual way of connecting is using devcert to create self signed certificates against a manually entered CA in the system, then modifying the hosts file with an entry such like this:

127.0.0.1     app.mycompany.local

Normally this allows developers to connect to their local instance and resolve the microfrontends to the staging environment.

Me, being the stubborn person that I am, use Windows with WSL. It has worked absolutely perfectly for years until this situation.

When I run the project on WSL, the server spins up fine, but when I try to access the website at https://app.mycompany.local/a-page I get a ERR_CONNECTION_REFUSED error on the browser. This is even more curious when I run a curl --verbose https://app.mycompany.local/a-page in the WSL console and I get a < HTTP/1.1 200 OK with the content of the page.

Anyone know how to deal with this situation?


Solution

  • I have resolved this by obtaining the IP address of the WSL2 system by running

    $ ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1492
            inet {WSL2_IP_ADDRESS}  netmask 255.255.240.0  broadcast 172.20.111.255
    

    and entering WSL2_IP_ADDRESS in my hosts file instead of 127.0.0.1.

    The address can also be obtained from the host Windows system by running

    > wsl hostname -I