Last active
December 24, 2015 02:39
-
-
Save tlewin/6731617 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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