Skip to content

Repository files navigation

Started life based on janl's io http://github.com/janl/io Other than some very 
basic structual similarities, this is a complete rewrite.

To install:
couchapp push url-shortener http://127.0.0.1:5984/urls

Create a short url:

curl -X POST http://127.0.0.1:5984/urls/_design/shortener/_update/shorten?target=http://zombo.com/

You should see:

  Shortened to ~439tppb

If you try to shorten the same url again, you should see a document conflict, 
since a shortened url already exists for that domain:
{"error":"conflict","reason":"Document update conflict."}

Get the redirect:

http://127.0.0.1:5984/urls/_design/shortener/_show/long/~439tppb

Example config running behind an Nginx reverse proxy:

location /~ {
    rewrite ^(.*)$ /urls/_design/shortener/_show/long$1 break;    
    proxy_pass http://127.0.0.1:5984;
}

For a list of shortened urls in the database see:
http://127.0.0.1:5984/urls/_design/shortener/_list/index/shorts

The main page for the app is:
http://127.0.0.1:5984/urls/_design/shortener/index.html

The shorten method uses a basic crc-32 checksum on a base64 encoded url, then 
returns a base36 string of the checksum. I ran a test on ~700,000 urls I 
downloaded from a blacklist site (probably the only good use for censorship). 
There is approximately 1 conflict per 10,000 urls. Most of the collisions 
occured with ranges of similar ip only urls.

About

url shortener couchapp based on janl's io

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages