My Stack
August 14th, 2022
I built my site straight on top of Rack. Why? Many years ago I had gotten so used to Rails and Sinatra that I paused and wondered, "what if I just did something on top of Rack?" And here I am. It's been a fun little exercise.
If you're familiar with the Rack interface it starts with the simple
config.ru
file. From here I just define my routes:
run Router.new([ { :name => 'posts', :path => %r{^/posts/}, :method => "GET", :route => Endpoints.posts }, { :name => 'root', :path => %r{^/}, :method => "GET", :route => Endpoints.root } ])My
Router
class then matches the request against one of
these routes. For example, the root route (/
) is
handled by Endpoints.root
and constructs the response
like so:
def root proc do |_env, _request_path| file = "#{__dir__}/index.html" response_for(file) end endMaybe a little dense if you haven't fiddled with Rack before, but I like how dead simple it is.
My front-end is equally simple. It's simply HTML with Holiday CSS.
But my site is more than just the code. For hosting I have my site
running on a DigitalOcean Droplet. And for deployment I manage that
with Dokku. Dokku is particularly important as it makes deployment
dead simple: git push dokku
and away it goes 🚀
One last thing which helped inform my choice of using DigitalOcean. I first started using it to play around with Dokku. I could ssh in, install my favorite packages (hello neovim!), mess something up, and start all over again with a new Droplet. Once I was done playing with Dokku I realized I could go subdomain crazy with very little trouble.
So, when I have a new idea, I can get it running by: forking my Rack app repo, getting my idea into code, deploying a database on my Droplet (maybe), provisioning a subdomain and configuring Dokku, and finally deploying it. It's really a great, tiny little platform for playing around with ideas.