Accessing a CommandBox Server Running Inside WSL

July 14, 2023    

My workflow for the last couple years has been to use WSL on my Windows workstation for as much as possible. I prefer to work this way because our production servers at work run Linux and I want to be as close to that environment as I can get. Luckily, it's possible to start a server inside WSL and hit it from your browser on Windows. Here's what you need to do.

The Config

Here's what you came for, with a quick explanation below the snippet.

File:server.json
{
"name":"mysite",
"web":{
"host":"0.0.0.0",
"http":{
"enable":true,
"port":3000
}
}
}

If modifying JSON isn't your jam, running server set web.host=0.0.0.0 gets you the same result and will automatically update your server.json file so the change is persisted for the future.

The key bit here is the web.host config. This will bind your server to all IP addresses in WSL. If you leave it out, you'll be able to access the server from within WSL but not from outside it.

Open your browser and head to http://localhost:3000 and you should see your CommandBox site.