peterldowns / localias

custom local domain aliases for local dev servers
MIT License
583 stars 3 forks source link

Clean up /etc/hosts #35

Closed gaetansenn closed 4 days ago

gaetansenn commented 3 weeks ago

Is there a way to clean up the /etc/hosts file after a daemon or process has been killed? In my case, I'm overriding a development environment, but sometimes I need to access it directly. To do so, I need to remove the redirections in the /etc/hosts file.

peterldowns commented 4 days ago

Is there a way to clean up the /etc/hosts file after a daemon or process has been killed?

Yes, there is a secret debug command for doing this.

# stop localias from running
localias stop

# Remove the localias entries from your /etc/hosts file.
# All other entires in the file will remain intact.
localias debug hostctl clear

# confirm that your hosts file is cleaned up
cat /etc/hosts

In my case, I'm overriding a development environment, but sometimes I need to access it directly.

Can you explain more? I recommend against using localias to "override" domains that would otherwise be valid. For instance, if you're using localias to sometimes redirect example.com to your local development version, and when you turn off localias example.com takes you to your production site, that's a bad idea.

To do so, I need to remove the redirections in the /etc/hosts file.

Are you sure? If you're not using conflicting names like I mentioned above, you should be able to visit your site without the alias just fine. For instance, if your alias is frontend.local -> localhost:8080, you can always just visit http://localhost:8080 in your browser, even if there is a rule for frontend.local in your /etc/hosts.

gaetansenn commented 2 days ago

Hi @peterldowns,

I'm doing this because the API of the client is using CORS and will only accept specified domains. The domain i'm using in dev mode is the stagging env so it's not a real problem. There is other case like this like the oauth provider, using some provider that accept limited custom domain ... Thank you for the secret debug command ;)