Combining puma-dev (for RoR projects) with regular localhost (for Next.js and node-type projects)

- Posted in development Uncategorized workflow

This is a blog post that I wish I didn’t have to write because it’s one of those annoying things that you just want to work.

Anyway, I am working on a Ruby on Rails project where I am using puma-dev.

But to prepare the templates, I spun up a little project using Pug and a combination of chokidar and browsersync to write the initial code in my preferred way.

I ran into a roadblock where I can run either my Rails project using puma-dev, or my node-based project, but not both at the same time.

When accessing the node-based project when puma-dev was running, I would run into this browser error:

This site can’t provide a secure connection
localhost sent an invalid response.
ERR_SSL_PROTOCOL_ERROR

The general idea behind puma-dev is that you would access your Ruby on Rails projects by linking their folders, and resolving them to a test domain.

For example the folder is called banana and you would be able to access your Ruby on Rails project at https://banana.test . It’s similar to an older project the old schoolers might know called dnsmasq.

Now, installing puma-dev messes with how IP addresses resolve on your system. When you follow the base instructions on their Github, you might find yourself in the same position as me: that your Next.js/Svelteki/regular node projects/or whatever that runs on localhost:xxx does not work anymore.

The culprit is that as part of the installation process, puma writes a file called test to /etc/resolver with the following contents:

# Generated by puma-dev
nameserver 127.0.0.1
port 9253

If I comment out this file, my setup works again. In general it’s good to know which symlinks exist, which you can check here:

cd ~/.puma-dev
ls

Normally this folder will contain a symlink to your project folder (which you previously linked with puma-dev link in the folder itself.

You can stop puma-dev with this command:

puma-dev -stop

You might get an error, after which you can try:

pkill puma-dev || true

It could be loaded in launchd (depending on how you set it up):

launchctl list | grep puma
# If you see io.puma.dev loaded:
launchctl remove io.puma.dev

In this situation, your Next.js/Sveltekit/Node.js projects will work.

If you then want to get back:

sudo puma-dev -setup
puma-dev -install
puma-dev

Now, how do we make both things work at the same time?

Well, turns out the solution is actually quite simple. Since puma-dev is hijacking 127.0.0.1 aka localhost, visit something else than localhost but point it to localhost.

To achieve this, add an entry to your /etc/hosts file:

127.0.0.1 localhost-workaround

Then, instead of visiting http://localhost:3000 – when Puma is on, visit http://localhost-workaround:3000. Done!

Leave a Reply

Your email address will not be published. Required fields are marked *