
The Magic of lvh.me: Testing Rails Subdomains in Development
The /etc/hosts Headache If you are building a SaaS that uses subdomains (like app.mysite.com or tenant.mysite.com ), testing them locally is usually a pain. The traditional way is to edit your /etc/hosts file: 127.0.0.1 mysite.local 127.0.0.1 app.mysite.local This is tedious, requires sudo privileges, and you have to remember to do it for every new tenant or project. There is a better way. It’s called lvh.me . What is lvh.me? lvh.me (Local Virtual Host) is a free service that simply points its DNS "A" record to 127.0.0.1 . Because it is a real registered domain name, it supports wildcards . This means: lvh.me points to 127.0.0.1 app.lvh.me points to 127.0.0.1 any-thing-you-want.lvh.me points to 127.0.0.1 You don't have to install anything. You don't have to configure any DNS. It just works. Step 1: The Rails Security Barrier Since Rails 6, there is a security feature that blocks "Host Header Attacks." If you try to visit http://lvh.me:3000 right now, Rails will show you a "Blocked Host
Continue reading on Dev.to Webdev
Opens in a new tab



