Setting public_folder twice, and the silent 404 that follows
Two small Sinatra experiments, one of which contains a bug worth keeping.
hello-sinatra is what it says. sinatra-stripe-office-hours is a Stripe
checkout with a static client served from the same process.
The bug is that server.rb sets public_folder twice, first to "../client",
then to a path built from ENV['STATIC_DIR']. In Sinatra set is
last-write-wins at load time, so the first line is dead code and the app’s
behaviour depends entirely on an environment variable being present. Unset, the
second assignment produces a nonexistent path, and the result is not an error.
It is a 404 on the index, which sends you looking at routes rather than at
configuration.
That is a good small example of a general thing: a line that appears to establish a default and establishes nothing, because it is overwritten unconditionally two lines later. Either the second expression needs a fallback or the first should go, and the file should not claim two answers.
A payment server and its client in one process is fine for an experiment: the secret key sits in a process also serving static files, and a card-entry page wants a tighter CSP than a hello world.