make localhost

Posted by jacqui maher on April 15, 2008 at 12:58 PM

Hey Rails developers: I bet you do the majority of your development locally, but work in an environment where you have various other development, staging, testing, and production servers.

I often have to check the same URL locally and on our staging or production servers. I got tired of selecting the hostname and changing it to “localhost:3000” and vice versa, so I made myself a bookmarklet. It is *really* easy to make a bookmarklet.

Here’s a bookmarklet that will replace everything up to the gTLD (I took this list from wikipedia) with “localhost:3000”. Drag it to your bookmarks toolbar, and the next time you’re on a url in your application that you’d like to view locally, just click it.

make localhost

here’s the source. enjoy…

   1  <a href="javascript:var current_url = location.href; var new_url = current_url.replace(/.*?(\.com|\.net|\.org|\.mil|\.info|\.gov|\.biz|\.jobs|\.int|\.pro|\.ae    ro|\.asia|\.cat|\.coop|\.edu|\.mobi|\.museum|\.name|\.travel|\.tel)\//, 'http://localhost:3000/'); location.href = new_url; ">make localhost</a>


I viewed that in my browser and dragged the link to my bookmarks toolbar. Now I can be on any of our servers ending in “.streeteasy.com” and in a single click view the page locally.

Comments

There is 1 comment on this post. Post yours →

A simple modification will let you use this snippet on country code TLDs as well: just replace the regexp with this:

/https?:\/\/[^\/]*\//

Post a comment

Required fields in bold.