cxspxr / react-shortener

:link: Rails API & React URL Shortener

Home Page:https://shorrtener.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

📮 Rails API for URL Shortening 📤

What I'm gonna use:


Development

Use rails s and curl for HTTP requests.


Deployment

This might be deployed as an isolated API as it is shown here (this exactly route returns the current number of links for base62 encoding). Along with a frontend like this (git for it) served with some http server. Just don't forget to respect the CORS as it is shown here.

On the other hand it could be deployed as a part of monolithic system as it is shown here (react branch of this repo) with a Puma for http serving.


Project Structure

app/

You may know the app/ structure since it's pretty default. It's the home to models, controllers, validators, exception handlers etc.

Controllers

There are three controllers which are interesting for us:

  • application_controller with module dependencies;
  • links_controller handles store-ing, get-ing, count-ing for the Link model;
  • redirect_controller with a single method to redirect and store the Redirect itself (i.e. it's location) using the Geocoder;

Models

  • Link to store :url and :shortened;
  • Redirect to store :location and :time;

A single Link has many Redirects. A single Redirect belongs to one Link.

Validators

  • Base62Validator to validate :base62 shortening;
  • UrlValidator to validate :url formatting;

config/

  • initializers/rack_attack.rb to configure Rack::Attack;

  • environments/*.rb to manage heroku production and local environments (development and testing);

spec/

This is for RSpec with Shoulda Matchers & Faker testing.

I belive that everything is backed by tests by now.

Specific files

.branch-ignore is used by me to manage branch-specific .gitignore using Husky and .gitignore.<branch-name> files.

/.*|(other)/ folders & files are pretty default