Sha256: 576bbfc3dbebf4dd5f10719129f5b9cc34af0e6984aced4973b60cd3c56b6261

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module Lamby
  module Debug
    include Lamby::SamHelpers

    extend self

    def on?(event)
      params = event['multiValueQueryStringParameters'] || event['queryStringParameters']
      (Rails.env.development? || ENV['LAMBY_DEBUG']) && params && params['debug'] == '1'
    end

    def call(event, context, env)
      [ 200, { 'Content-Type' => 'text/html' }, [body(event, context, env)] ]
    end

    private

    def body(event, context, env)
      <<-HTML
        <!DOCTYPE html>
        <html>
          <body>
            <h1>Lamby Debug Response</h1>
            <h2>Event</h2>
            <pre>
              #{JSON.pretty_generate(event)}
            </pre>
            <h2>Rack Env</h2>
            <pre>
              #{JSON.pretty_generate(env)}
            </pre>
            <h2>#{context.class.name}</h2>
            <code>
              #{CGI::escapeHTML(context.inspect)}
            </code>
            <h2>Environment</h2>
            <pre>
              #{sam_local? ? JSON.pretty_generate(ENV.to_h) : 'N/A'}
            </pre>
          </body>
        </html>
      HTML
    end

  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
lamby-2.1.0 lib/lamby/debug.rb
lamby-2.0.1 lib/lamby/debug.rb
lamby-2.0.0 lib/lamby/debug.rb
lamby-no-rails-1.0.3 lib/lamby/debug.rb
lamby-1.0.2 lib/lamby/debug.rb
lamby-1.0.1 lib/lamby/debug.rb
lamby-1.0.0 lib/lamby/debug.rb