Skip to content

Instantly share code, notes, and snippets.

@albertico
Created March 5, 2014 02:04
Show Gist options
  • Save albertico/9359866 to your computer and use it in GitHub Desktop.
Save albertico/9359866 to your computer and use it in GitHub Desktop.
Goliath server with CORS middleware
#!/usr/bin/env ruby
require 'goliath'
class CORS
include Goliath::Rack::AsyncMiddleware
def post_process(env, status, headers, body)
headers['Access-Control-Allow-Origin'] = '*'
[status, headers, body]
end
end
class HelloWorld < Goliath::API
use CORS
def response(env)
[200, {}, "hello world"]
end
end
# ruby goliath_cors.rb -sv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment