Puma
Puma is a modern, concurrent web server for Ruby and Rack applications. Designed with speed and simplicity in mind, Puma is known for its ability to handle multiple requests simultaneously, making it a popular choice for serving Ruby on Rails applications in both development and production environments.
Simplify Local Rails Development with Puma-dev
Developing Rails applications locally can be a hassle, especially when we want to run multiple Rails applications on our machine. Doing that with localhost:3000
will get annoying at some point (cookie sharing, changing ports, everyone in the team handling it differently, no HTTPS to test with…).
for example we have to run multiple servers to run the app and API.
Working on a system like this locally requires developer to run multiple Rails servers in multiple terminal windows.
Thankfully, we can make this process much easier with puma-dev.
Puma-dev
Puma-dev is a tool that provides a quick
and easy way to manage Puma-powered web apps in development on macOS
and Linux. We can run
and manage our applications without needing to tweak our /etc/hosts
file or constantly start
and stop individual servers. Access them using the .test
subdomain,
and run multiple custom domains at the same time.
With puma-dev, each app gets its own subdomain, making local development more seamless and organized.
The servers started by puma are centrally managed. Once puma-dev accepts an HTTP access, the puma server is started automatically. It automatically sleeps if there is no access for a while. As stated above, server operations are managed by puma-dev without any manual operation.
Key features of puma-dev include:
- Easy startup and idle shutdown of rack/Rails apps.
- Easy access to apps using the .test subdomain (configurable).
- Support for running multiple custom domains simultaneously, e.g. .test, .puma.
- Support for HTTPS out of the box.
- Support for Rails 5 ActionCable via rack.hijack websockets.
Using puma-dev
Prerequisites:
Before we start, ensure we have the following installed:
- macOS or Linux (puma-dev is designed for these platforms)
- Ruby (version 2.5+)
- Bundler
- Rails (version 5.0+)
Installing puma-dev
To install puma-dev, follow these steps:
- Install puma-dev:
On macOS or GNU/Linux, we can use Homebrew:
we can also download the appropriate binary from the puma-dev releases page https://github.com/puma/puma-dev/releases and place it in our PATH.
- Set up puma-dev:
- Start puma-dev:
Here are the few useful commands of puma-dev:
Configuring our Rails Application
With puma-dev installed, we need to configure our Rails application to work with it.
Step 1
We need to be using Puma as our Rails development web server.
Step 2
In development ensure that our Rails app is configured to allow requests from host.
Step 3
For puma-dev to run our application, we have to symlink the application directory into ~/.puma-dev
with the help of puma-dev link
command.
our application will now be available at https://app_name.test
. Here is the url of above example: https://miru.test
.
Update bin/setup
When working as a team, it’s beneficial to know the domain that other developers are using for local application development.
To ensure everyone uses the same URL, we can add the puma-dev link
command to our Rails bin/setup
file instead of running it manually.
By running bin/setup
we get a consistent development environment with a consistent URL.
The recent Rails PR #51088 suggests adding puma-dev configuration to the bin/setup
script. Here’s how we can do it:
With out any manual input from the developer, above bin/setup
script installs puma-dev
if not installed in the local machine
and takes care of all the necessary configurations regarding the installion process. After installing, it also set’s the domain for the app to run.
our application will now be available at https://app_name.test
.
Conclusion
Puma-dev is a powerful tool for developers working with multiple Ruby web applications. It avoids the headache of managing multiple Rails servers in multiple terminal windows by running a background process to manage all the Rails apps along with features like custom domain support and easy start/stop commands, makes it an essential part of development workflow on macOS and Linux.
By integrating puma-dev
configuration into our bin/setup
script, we can make it easy for our entire team to get up
and running quickly, without having to worry about managing the local server setup.