Skip to content

Instantly share code, notes, and snippets.

@tlewin
Last active December 24, 2015 02:39
Show Gist options
  • Save tlewin/6731617 to your computer and use it in GitHub Desktop.
Save tlewin/6731617 to your computer and use it in GitHub Desktop.
require 'goliath'
module Goliath
class Request
old_post_process = instance_method(:post_process)
define_method(:post_process) do |results|
status, headers, body = *results
# Include any data here
# All requests will pass here
if env[:any] # my test condition
headers['Access-Control-Allow-Origin'] = '*'
end
old_post_process.bind(self).call(results)
end
end
end
class Hello < Goliath::API
include Goliath::Validation
def on_headers env, headers
# Include any logic here
if env['QUERY_STRING'] =~ /x/
env[:any] = true
raise Goliath::Validation::NotFoundError.new('It happens')
end
end
def response env
[200, {}, 'Hello World!']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment