UrlGrey, Picard's favorite URL shortener
UrlGrey is a URL shortener written in Rails 5, backed by PostGres (or whatever you want, just change
database.yml). The best part is its ability to redirect the root URL to allow for a bare domain vanity URL (try hitting https://grz.li and see where it takes you!).
- Get a vagrant box (recommend Ubuntu, specifically mine because it comes with RBENV and the right Ruby versions out of the box.
- Clone this repo into the vagrant machine's shared directory (if using the above box, it'll be
.../machine_dir/share, which is linked to
/var/www/appson the VM.
- Get onto the vagrant machine, and create a Postgres role for the application:
- Start the
sudo -u postgres psql
- Once in the
psql$ create role url_shortener_user with createdb login password 'some_password';
- Put that password for the Postgres role into your environment:
echo "export URL_SHORTENER_DB_PASSWORD='some_password'" >> ~/.zshrc(or whatever shell profile is appropriate for your setup).
- Install all the dependencies:
- if this is a new ruby to your system, don't forget
gem install bundler
- Create the dev and test databases:
bundle exec rails db:create.
- Run it up:
bundle exec rails s -p 3001; also you can use
If you want to reserve any URL slugs from use, do so in
config/initializers/reserved_slugs.rb. It is currently just the slugs that would break the application:
The app has some basic configurations that should be set in
config/application.rb before deploying it for yourself. Currently, this is just to enable the special root url redirect, and to rename the application to suit your own tastes. Maybe you prefer coffee, and have some awesome coffee/URL pun instead of 'Url Grey'?
- Set the application host: `config.application_host = 'https://your.domain'
- To rename the application, change:
config.application_name = 'URL Grey'
- To configure the root redirect, before deploying the app, change the first
ShortUrlseed's redirect value
- This can also be changed like any other redirect once the app is running. Just find the 'root' redirect
- To disable the root redirect, set
config.root_redirect_enabled = trueto
If you run into an issue where PostgreSQL shouts at you about some ForeignKeyViolation or something, it seems it's because ActiveRecord disables foreign key insertion before running tests. Easiest solution is to run:
sudo -u postgres psql
psql$ alter role url_shortener_user superuser; # ONLY DO THIS IN DEV AND TEST ENVIRONMENTS!!!
Credits to this post
Be sure to set the following environment variables:
ROOT_REDIRECT_URL before deploying to live (latter only if you want to use the root URL as a redirect as well).
This is currently being built so that only registered users can see other users... and the only way to create users is to have an admin do so.
To change this, first, mess around with the
before_action filters in
users_controller.rb, then make sure that the layouts are exposing the right forms/links.
- user creation, editing, display, deletion
- password resets for existing users (currently would have to be done by an admin)
- emailing users once created and prompting them to set passwords (currently set by admin)
- implement shortening and redirection
- random short URL generation
- special root url redirect for super amazeballs vanity urls
- vanity/custom short URLs
- reserving application routes as slugs (though this could get better)
- URL search and reverse search for checking if a short URL destination already exists, or if a slug is taken
- move search into its own controller so results don't appear behind the
/adminpath (because they're visible to anonymous users)
- disallow the applications own domain as a redirection destination (hello infinite loop!)
- displaying short URL stats
- number of hits
- in last month
- graph of usage over time
- most popular short URLs
- source of traffic
- number of hits
- clean up layouts so they're more consistent with columns
- refactor root url redirection to use a config screen and the app settings database table
(C) 2017 Sean Moran-Richards/Flying Grizzly. Licensed under the MIT License.
Check out the todo list above, fork the app, make a change in a sensibly-named feature branch, and create a PR!