Creating My Own URL Shortener
Posted by matijs 11/04/2010 at 12h22
Because URL shortening services can go away at any time, I decided to install my own. In the spirit of your-own-dogfood, and to make hacking it as enjoyable as possible, it had to be in Ruby (this ruled out YOURLS, which otherwise does exactly what I want). There are tons of URL shortening projects in Ruby on GitHub. Unfortunately, they all lacked one feature: password protection for the adding of URLs. In the end, I picked a nice simple one and changed it to my liking. The result can be found in my fork of turl.
Why is this safer than using one of the existing services? The reason tr.im went under is that they couldn't make it pay for itself, and there was a lot of abuse from spammers. Both problems are absent for my own service: I don't need to make any money off of it, and I'm the only one who can create new short URLs.
Some observations on developing this software:
-
For a small project like this, putting everything in one file is very, very nice. Ramaze allows you to do this (as do other frameworks), Ruby on Rails does not. I wonder how seamless the transition is if your project starts small like this and then gradually becomes big enough that you need to split it into different files.
-
Ramaze's documentation needs some love. Everything is documented well in principle, but with the split-off of the
innate
library, it took me ages to find the documentation for thea
method and friends. -
I really like the idea of
[Sequel][sq]::Model
where you define the table schema right in the model. I'm not sure how or how well it works with migrations, but for a small project like this, it's nice and clean. -
Ramaze could use some more options for session storage. In particular, something file-based shouldn't be too much to ask for. I'm using the LocalMemCache option, and keep having to log in.
I really like Ramaze, and am eager to try Sinatra. I have been ignoring these more light-weight frameworks for far too long.