module Lamby module Debug extend self def on?(event) params = event['multiValueQueryStringParameters'] || event['queryStringParameters'] (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
#{JSON.pretty_generate(event)}
#{JSON.pretty_generate(env)}
#{CGI::escapeHTML(context.inspect)}
HTML
end
def development?
ENV.to_h
.slice('RACK_ENV', 'RAILS_ENV')
.values
.any? { |v| v.to_s.casecmp('development').zero? }
end
end
end