Recently, after a brief outage at work, I wondered if it would be possible to replicate the problem locally using Laravel Valet. My Google search landed on this StackOverflow post, where the answers shot down the idea. Not to be dissuaded by something I read on the internet, I started investigating if it was possible and stumbled upon what I think is a viable solution. There aren't very many hoops to jump through or major quirks so I believe it's not only possible but could be supported out of the box.
In my case, I want to proxy the domain
scdn-app.thinkorange.com through my local version of the Laravel application.
~/.config/valet/config.jsonon macOS and change the
valet link scdn-app.thinkorangeto set up our valet configuration to point the domain to this directory.
valet secure scdn-app.thinkorangeto set up the SSL certificate.
cp tld-test.conf tld-com.conf.
address=/.com/127.0.0.1and save the file.
valet isolate --site scdn-app.thinkorange firstname.lastname@example.org.
/etc/hostsfile to redirect the domain to
127.0.0.1for ipv4 and
::1. I use the excellent Gas Mask to make this step easier.
Now we should have a functional production proxy through our local machine. This configuration creates a few problems around keeping the
Fortunately, a few extra steps are necessary for us to switch back to
.test while also keeping this site functional.
~/.config/valet/config.jsonagain and change the
test. This change will immediately break our site.
ls -alto list the directory, we'll see our site
scdn-app.thinkorange. Let's change that.
mv scdn-app.thinkorange scdn-app.thinkorange.com.
Our site should now be working again. We are also able to continue serving our previous local test domains.
Because we can create a permanently functional system using these steps, I believe it should be possible to create a pull request to reduce the number of hoops we have to jump through.
I'd love to be able to run
valet link scdn-app.thinkorange.com. with a period at the end to denote I'm including the full domain with TLD.
That would eliminate the temporary step of editing the
config.json file, and the
Sites directory would just work(TM) as it would include the
.com directory name.
I don't believe we even need the dnsmasq changes as I'm able to navigate to a functional site without them.
I believe Gas Mask is doing the work, but it's better to be safe than sorry.
If you'd prefer a YouTube video where I stumble through recreating these steps from scratch: