Search code examples
ruby-on-railsrackthin

Thin Server - Virtual Path


In production, we deploy our application to a virtual path:

https://hostname/my-virtual-path/

So the route '/users/' in development is actually accessed on https://hostname/my-virtual-path/ in production.

This means that routes are different between development (/users/) and production (/my-virtual-path/users/). Normally this is handled by setting the environment variable RAILS_RELATIVE_URL_ROOT or config.action_controller.relative_url_root so the paths Rails generates with its URL helpers is adjusted depending on the setting of these variables. Unfortunately, our assets are going to be pre-compiled BEFORE we know what this setting will be.

Is there a way to run a Rails server in development mode, using thin, that will serve files to a virtual path? For example, I want to type:

thin start --ssl -p 3000 --path whatever-i-want

and be able to access the root URL at https://localhost:3000/whatever-i-want in order to test my application.


Solution

  • I think you’re after the --prefix option. From the output to thin -h:

    --prefix PATH                Mount the app under PATH (start with /)
    

    In your case something like this:

    thin start --ssl -p 3000 --prefix /whatever-i-want 
    

    (Note you need to start the prefix with /.)