Sha256: c37d167443c91418a58ced20aa8e98eb5d984a26c9f81bd50fa5ea147d91a142

Contents?: true

Size: 543 Bytes

Versions: 2

Compression:

Stored size: 543 Bytes

Contents

class TranslationEngine::KeysMiddleware

  URL_PATH = /\A\/translation_engine\/keys/

  def initialize(app)
    @app = app
  end

  def call(env)
    if env['PATH_INFO'] =~ URL_PATH
      handle_redirect_request(env)
    else
      @app.call(env)
    end
  end

  private

  def handle_redirect_request(env)
    key_path = env['PATH_INFO'].gsub(URL_PATH, '')

    [
      302,
      {
        'Location' => "#{TranslationEngine.api_host}/#{key_path}",
        'Content-Type' => 'text/html'
      },
      ['Moved Temporarily']
    ]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
translation_engine-0.0.2 app/middlewares/translation_engine/keys_middleware.rb
translation_engine-0.0.1 app/middlewares/translation_engine/keys_middleware.rb