I am using WSL2 (Ubuntu) to develop a React application built using Vite. When running the npm run dev command, the terminal reports that the server is running on localhost:8080, but:
My goal is to ensure that port 8080 is actually listened to and accessible inside WSL2 (for example, via curl http://localhost:8080 ).
Run Vite with --host 0.0.0.0
to make it listen on all network interfaces:
vite --port 8080 --host 0.0.0.0
Or in package.json
:
"scripts": {
"dev": "vite --port 8080 --host 0.0.0.0"
}
Then, inside WSL2, get your Windows host IP:
ip route | grep default
You’ll see something like default via 172.27.208.1
. Use that IP:
curl http://172.27.208.1:8080
Now it works from inside WSL2!