Sha256: c34df925697ef152a50a1dd3a316c363f7eac7094be065a9eeb641ce4e110aea

Contents?: true

Size: 768 Bytes

Versions: 47

Compression:

Stored size: 768 Bytes

Contents

# frozen_string_literal: true

module ZuoraConnect
  module Middleware
    # Enables requests to be served from dynamic paths, determined by headers
    class Hallway
      UI_PATH = 'HTTP_ZUORA_UI_PATH'
      LAYOUT_ID = 'HTTP_ZUORA_LAYOUT_FETCH_TEMPLATE_ID'

      def initialize(app)
        @app = app
      end

      def call(env)
        dynamic_path = env[UI_PATH].presence || layout_id(env)

        Thread.current[:isHallway] = dynamic_path

        if dynamic_path.present?
          env['SCRIPT_NAME'] = dynamic_path
          env['PATH_INFO'] = env['PATH_INFO'].sub(dynamic_path, '')
        end

        @app.call(env)
      end

      private

      def layout_id(env)
        "/#{env[LAYOUT_ID]}" if env[LAYOUT_ID].present?
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
zuora_connect-3.0.2.pre.k lib/zuora_connect/middleware/hallway.rb
zuora_connect-3.0.2.pre.j lib/zuora_connect/middleware/hallway.rb
zuora_connect-3.0.2.pre.i lib/zuora_connect/middleware/hallway.rb
zuora_connect-3.0.2.pre.h lib/zuora_connect/middleware/hallway.rb
zuora_connect-3.0.2.pre.g lib/zuora_connect/middleware/hallway.rb
zuora_connect-3.0.2.pre.f lib/zuora_connect/middleware/hallway.rb
zuora_connect-3.0.2.pre.e lib/zuora_connect/middleware/hallway.rb