Routing Issue: Blank Page When Routing Ruby on Rails Admin Section to "/admin" Route

1. The problem I’m having:

I basically have to serve static files (front end in React) of the app at domain.com and the admin section (ROR) at domain.com/admin. So, as I’m trying to route the admin section of my Ruby on Rails application to the /admin route,

I tried routing the admin section to just my domain.com and it’s working flawlessly. However, as soon as I route it to /admin, I’m getting a blank page and it’s not getting routed.

2. Caddy version:

v2.7.6

3. How I installed and ran Caddy:

a. System environment:

Ubuntu 20.04.6 LTS

b. Caddyfile config:

mydomain.com {
    root * /var/www/site
    file_server
    
    @admin {
        path /admin/*
    }
    
    reverse_proxy @admin localhost:4322
}

That’s because there’s nothing in your Caddyfile that handles requests to /admin, only /admin/. The slash is significant, and sometimes not having it will break front end pages.

Also you can just write it inline: reverse_proxy /admin/* …

3 Likes

To add onto that; you could either change it to /admin*, or add redir /admin /admin/ to make sure the leading slash always exists (which is ideal, to have a canonical URL).

3 Likes

Yeah, I tried that, but it didn’t work either.
Could it be a Ruby back-end issue? Because it works perfectly when the configuration is like this:

mydomain.com {
    reverse_proxy  localhost:4322
}

but as soon as I route it to /admin, it just shows me a blank white page.

Sure, Thanks!

If your upstream app doesn’t know about /admin then it makes sense that it wouldn’t work.

You’d probably be better off making a subdomain like admin.example.com and serve it from there, if you need to continue serving a static site at your apex domain.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.