What I'm gonna use:
-
Rails API 5.2.1
-
RSpec for testing
-
Shoulda Matchers for simplier
RSpec
testing -
Heroku for deployment & development
-
Husky to manage GIT hooks & to run
RSpec
test onpre-commit
&pre-push
-
Rack::Attack to prevent DOS
-
Rack CORS for Cross-Origin Resource Sharing
-
Memcached/Dalli for requests throttling
-
Geocoder to track locations
Use rails s
and curl for HTTP requests.
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.
You may know the app/
structure since it's pretty default. It's the home to models
, controllers
, validators
, exception handlers
etc.
There are three controllers which are interesting for us:
application_controller
with module dependencies;links_controller
handlesstore
-ing,get
-ing,count
-ing for theLink
model;redirect_controller
with a single method toredirect
and store theRedirect
itself (i.e. it's location) using the Geocoder;
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
.
Base62Validator
tovalidate :base62
shortening;UrlValidator
tovalidate :url
formatting;
-
initializers/rack_attack.rb
to configure Rack::Attack; -
environments/*.rb
to manage herokuproduction
and local environments (development
andtesting
);
This is for RSpec with Shoulda Matchers & Faker testing.
I belive that everything is backed by tests by now.
.branch-ignore
is used by me to manage branch-specific .gitignore
using Husky and .gitignore.<branch-name>
files.