Created
November 21, 2011 21:35
-
-
Save elucid/1384021 to your computer and use it in GitHub Desktop.
Running multiple Goliath apps
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' | |
require 'yajl' | |
# adapted from goliath/examples/async_upload.rb | |
class AsyncUpload < Goliath::API | |
use Goliath::Rack::Params # parse & merge query and body parameters | |
use Goliath::Rack::DefaultMimeType # cleanup accepted media types | |
use Goliath::Rack::Render, 'json' # auto-negotiate response format | |
def on_headers(env, headers) | |
env.logger.info 'received headers: ' + headers.inspect | |
env['async-headers'] = headers | |
end | |
def on_body(env, data) | |
env.logger.info "received #{data.size} bytes of data" | |
(env['async-body'] ||= '') << data | |
end | |
def on_close(env) | |
env.logger.info 'closing connection' | |
end | |
def response(env) | |
[200, {}, {body: env['async-body'].size.to_s, head: env['async-headers']}] | |
end | |
end |
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' | |
class OtherEndpoint < Goliath::API | |
def response(env) | |
[200, {}, "this is the other endpoint"] | |
end | |
end |
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
$:.unshift '.' | |
require 'goliath' | |
require 'other_endpoint' | |
require 'async_upload' | |
class Router < Goliath::API | |
map '/other_endpoint' do | |
run OtherEndpoint.new | |
end | |
map '/async_upload' do | |
use Goliath::Rack::Validation::RequestMethod, %w(POST) | |
run AsyncUpload.new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment