2.7 KiB
roda-templates
For the single file app template, really the only file you need is the config.ru and run it with puma.
Views
Next iteration:
adding plugin csrf, and maybe public, assets
split out app routes from config.ru
set up view templates
add unreloader
future iterations will add database, then authentication
Setup
Prereq installs
Will need ruby; install it via package manager or a ruby manager like rbenv/ruby-build. Will need the roda gem, and then an application server such as puma (recommended), gunicorn, or passenger. My examples will use system ruby and puma.
Option 1: System wide packages
With this example, will basically just ignore the project's Gemfile. Debian 12 has a pretty current ruby version so just using it.
sudo apt install ruby ruby-rack puma ruby-erubi ruby-tilt
sudo gem install roda rack-unreloader
Option 2: Bundler
Run the bundle command from the project's root directory
sudo apt install ruby ruby-bundler
bundle config set --local path 'vendor/bundle'
bundle install
Run it
In the project root directory:
puma
This default to development mode. Run it in production mode with:
RACK_ENV=production puma
For development, just run it like that. For production, probably want to set up a systemd service.
Run it with systemd in production
Copy the example myapp.service file to /etc/systemd/system/ and edit accordingly. The example assumes a user named "myapp" with a group name "myapp", the application files are in /opt/myapp/, and puma is the system puma.
Notes
Unreloader
This has puma reload with any file changes while you are working on the app, when in development mode. When puma is in production mode, it loads the app on startup like normal with no performance penalty. It's very useful during development and no reason to not leave it in.
https://github.com/jeremyevans/rack-unreloader.
Basically, you require the app from the config.ru, and then within you app files, any "require_relative" will be "Unreloader.require" instead, plus you do need to include the file extension.
In config.ru, the "dev =" line stores true or false depending on the RACK_ENV environment variable (see above for changing from default development). Then the ":reload=>dev" uses the dev variable to tell Unreload to reload files or not. Lastly the "run" command uses dev variable to choose between running Unreloader, or bypass Unreloader and run App like normal in production.
Additional credit
I took a lot of inspirations from Jeremy Evans roda-sequel-stack. Jeremy Evans is the author of Roda and also Unreloader, Sequel, and a ruby core contributor.