Several applications using a single code base in ruby

I'm trying to get a reasonable idea of ​​how you can create an application on top of rubies / racks (or, even better, an existing structure) that manages something that is equivalent to WordPress. In particular, with the ability to serve multiple sites from the same code base, each of which has its own functions and configuration.

Suppose, for example:

  • example.com using auth, pages, blog modules.
  • forum.example.com → auth, forum modules
  • api.example.com → auth, api modules

This test case seems to work, including in a production environment:

# test.rb
class Foo
end

# config.ru
require 'rack'

use Rack::ShowExceptions
use Rack::CommonLogger

run lambda { |env|
  case env['HTTP_HOST']
  when /^test\./
    require './test'
    # answers true, regardless of subdomain loaded first
    [200, {'Content-Type'=>'text/plain'}, "#{Kernel.const_defined? :Foo}"]
  else
    # answers false, regardless of subdomain loaded first
    [200, {'Content-Type'=>'text/plain'}, "#{Kernel.const_defined? :Foo}"]
  end
}

Mostly working in environments with little, if any, so far, I'm a little nervous that this can come back and bite me along the way.

, / , ? ( - ? , , ? .., , .)

, ?

( Rails , . , . , , , example.com/site1, example.com/site2 .. )


, :

+1
1

, , , . Rails, -. , Nginx .

, , Rails . Engine.

, . , , , .

. Rails, .

0

All Articles