[Tip For Developer] Surfing the website that needs custom-host without manually customizing the host file

Duy KN
1 min readMar 16, 2022

The situation is you have a set of projects, which need to develop on your local machine. You need to run them by using specific domains to avoid the complexity of configuration.

This tip is working on macOS. I haven’t had tested on another platform, but IMO it works. I make use of the Google Chrome CLI (Canary version) parameter to set up custom host mapping. You can find Google Chrome Canary here. I choose Canary in favor of separating the personal use purpose with working purpose.

After installing, you can start it using bash:

#browser.sh/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --incognito --host-resolver-rules="MAP *.your-awesome-domain.com 127.0.0.1" &

Two main points here:

  • incognito Start browser in incognito mode
  • host-resolver-rules: mapping your domain to IP. For this example, it is localhost IP

Put the copy of this piece of script for your projects with some customs and save your time.

P/S: I’ve found a cheat sheet here https://peter.sh/experiments/chromium-command-line-switches/

Good luck.

--

--