I am new to Rails and Rack, but this guy had a seemingly simple record of using Rack to implement middleware for a dynamic domain session . The code looks pretty good, and I implemented it here on my local machine, but I still can’t go beyond the top level domains in one login.
Here's the code for the intermediate code:
class SetCookieDomain
def initialize(app, default_domain)
@app = app
@default_domain = default_domain
end
def call(env)
host = env["HTTP_HOST"].split(':').first
env["rack.session.options"][:domain] = custom_domain?(host) ? ".#{host}" : "#{@default_domain}"
@app.call(env)
end
def custom_domain?(host)
domain = @default_domain.sub(/^\./, '')
host !~ Regexp.new("#{domain}$", Regexp::IGNORECASE)
end
end
And then in environment.db:
config.load_paths += %W(
Finally, in the production.db (and development.db) file:
config.middleware.use "SetCookieDomain", ".example.org"
Any help is greatly appreciated.
EDIT: I am running Rails 2.3.3 and Rack 1.0
Tim B.
source
share