Platinum Partner

Add A Fake Host For Development Purposes

I don't like all these "localhost:3001", "localhost:3001", etc. urls so I use vhosts in apache (that is a proxy balancer for a mongrel cluster on my machine. This script helps me to add required information for my fake domain in the /etc/hosts and apache configs


HOSTS_FILE = "/etc/hosts"
VHOSTS_FILE = "/Library/Apache2/conf/extra/httpd-vhosts.conf"

if $*.size < 2
  puts %{addhost.rb - creates a fake domain and bind it to the working rails app
USAGE: addhost development_hostname mongrel_port

Example: if you have a rails app on a localhost:3002 and you want
         to bind it to the than run:
         addhost 3002
  exit 1

dev_host = $*[0]
mongrel_port = $*[1]

# Adding to the hosts file (absolute path must be in the HOSTS_FILE; usually /etc/hosts)
unless =~ /^\t#{dev_host}$/, "a") do |file|
    file << "\n127.0.0.1\t#{dev_host}"

unless =~ /^\tServerName #{dev_host}$/, "a") do |file|
    file << %{

  ServerName #{dev_host}
  ProxyPass / http://#{dev_host}:#{mongrel_port}/
  ProxyPassReverse / http://#{dev_host}:#{mongrel_port}
  ProxyPreserveHost on

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ }}
{{ parent.authors[0].realName ||}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks