<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: hosts code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 19:40:47 GMT</pubDate>
    <description>DZone Snippets: hosts code</description>
    <item>
      <title>Add a fake host for development purposes</title>
      <link>http://snippets.dzone.com/posts/show/3567</link>
      <description>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&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/local/bin/ruby&lt;br /&gt;&lt;br /&gt;HOSTS_FILE = "/etc/hosts"&lt;br /&gt;VHOSTS_FILE = "/Library/Apache2/conf/extra/httpd-vhosts.conf"&lt;br /&gt;&lt;br /&gt;if $*.size &lt; 2&lt;br /&gt;  puts %{addhost.rb - creates a fake domain and bind it to the working rails app&lt;br /&gt;    &lt;br /&gt;USAGE: addhost development_hostname mongrel_port&lt;br /&gt;&lt;br /&gt;Example: if you have a rails app on a localhost:3002 and you want&lt;br /&gt;         to bind it to the myrailsapp.dev than run:&lt;br /&gt;         addhost myrailsapp.dev 3002&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  exit 1&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;dev_host = $*[0]&lt;br /&gt;mongrel_port = $*[1]&lt;br /&gt;&lt;br /&gt;# Adding to the hosts file (absolute path must be in the HOSTS_FILE; usually /etc/hosts)&lt;br /&gt;unless IO.read(HOSTS_FILE) =~ /^127.0.0.1\t#{dev_host}$/&lt;br /&gt;  File.open(HOSTS_FILE, "a") do |file|&lt;br /&gt;    file &lt;&lt; "\n127.0.0.1\t#{dev_host}"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;unless IO.read(VHOSTS_FILE) =~ /^\tServerName #{dev_host}$/&lt;br /&gt;  File.open(VHOSTS_FILE, "a") do |file|&lt;br /&gt;    file &lt;&lt; %{&lt;br /&gt;&lt;VirtualHost *:80&gt;&lt;br /&gt;  ServerName #{dev_host}&lt;br /&gt;  &lt;br /&gt;  ProxyPass / http://#{dev_host}:#{mongrel_port}/&lt;br /&gt;  ProxyPassReverse / http://#{dev_host}:#{mongrel_port}&lt;br /&gt;  ProxyPreserveHost on&lt;br /&gt;&lt;/VirtualHost&gt;&lt;br /&gt;    }&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 22 Feb 2007 16:39:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3567</guid>
      <author>iwanttodeletemyaccount ()</author>
    </item>
    <item>
      <title>Quickly append a short hostname alias to /etc/hosts</title>
      <link>http://snippets.dzone.com/posts/show/1564</link>
      <description>&lt;code&gt;sudo echo -e "`dig +short che.st a`\tc" &gt;&gt; /etc/hosts&lt;/code&gt;</description>
      <pubDate>Fri, 24 Feb 2006 05:30:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1564</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
