Sha256: 08742e76b39a4cfd5fe8f6f73cfec0655df75fab0994ea09a7c5dfa51ba13608

Contents?: true

Size: 491 Bytes

Versions: 3

Compression:

Stored size: 491 Bytes

Contents

require 'rack'

module Rack

  module Rewritten

    class Subdomain

      def initialize(app, *fqdns)
        @app = app
        @fqdns = fqdns
      end

      def call(env)
        puts "-> Rack::Rewritten::Subdomain"
        req = Rack::Request.new(env)

        @fqdns.each do |n|
          if req.host =~ /(.+)\.#{n}$/
            env["SUBDOMAIN"] = $1
            env["FQDN"] = n 
            break
          end
        end

        @app.call(env) 
      end

    end

  end

end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rewritten-0.2.2 lib/rack/subdomain.rb
rewritten-0.2.1 lib/rack/subdomain.rb
rewritten-0.2.0 lib/rack/subdomain.rb