Sha256: 4e1242ced823a0b4dc7f9e045e756dd2626a26f54c6c3e74c5851e0a4f6f232f

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module RestPack::Web::Rack
  class Domain
    def initialize(app)
      @app = app
    end

    def call(env)
      identifier = Rack::Request.new(env).host

      response = Commands::Core::Domain::ByIdentifier.run({
        identifier: identifier,
        include: 'applications'
      })

      if response.status == :ok
        domain = response.result[:domains][0]
        application = response.result[:applications][0]

        env['restpack'] ||= {}
        env['restpack'][:domain] = domain
        env['restpack'][:application] = application
        env['restpack'][:application_id] = application[:id]

        env['restpack.session.options'] ||= {}
        env['restpack.session.options'][:key] = 'restpack.session'
        env['restpack.session.options'][:secret] = domain[:session_secret]
        env['restpack.session.options'][:domain] = domain[:identifier]
      else
        #TODO: GJ: better exceptions based on response status
        raise "[#{identifier}] is not a RestPack domain"
      end

      @app.call(env)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restpack_web-0.4.1 lib/restpack_web/rack/domain.rb
restpack_web-0.0.5 lib/restpack_web/rack/domain.rb