run.rb
# This example shows you how to embed Sinatra into your EventMachine
# application. This is very useful if you're application needs some
# sort of API interface and you don't want to use EM's provided
# web-server.
This example shows you how to embed Sinatra into your EventMachine
application. This is very useful if you're application needs some
sort of API interface and you don't want to use EM's provided
web-server.
This example shows you how to embed Sinatra into your EventMachine application . This is very useful if you ' re application needs some sort of API interface and you don ' t want to use EM ' s provided web - server .
def run(opts)
  EM.run do
  	@@db = EM::Mongo::Connection.new('localhost').db('foo_development')
  	@@collection = @@db.collection('my_collection')
    server  = opts[:server] || 'thin'
    host    = opts[:host]   || '0.0.0.0'
    port    = opts[:port]   || '8181'
    web_app = opts[:app]
       get '/hello' do
         'hello!'
       end
       get '/goodbye' do
         'see ya later!'
       end
     Then I will get the following:
       mapping: '/'
       routes:
         /hello
         /goodbye
       mapping: '/api'
       routes:
         /api/hello
         /api/goodbye
    dispatch = Rack::Builder.app do
      map '/' do
        run web_app
      end
    end
     NOTE that we have to use an EM-compatible web-server. There
     might be more, but these are some that are currently available.
    unless ['thin', 'hatetepe', 'goliath'].include? server
      raise "Need an EM webserver, but {server} isn't"
    end
     Start the web server. Note that you are free to run other tasks
     within your EM instance.
    Rack::Server.start({
      app:    dispatch,
      server: server,
      Host:   host,
      Port:   port,
      signals: false,
    })
  end
end
def run ( opts ) EM . run do @@db = EM :: Mongo :: Connection . new ( 'localhost' ) . db ( 'foo_development' ) @@collection = @@db . collection ( 'my_collection' ) server = opts [ :server ] || 'thin' host = opts [ :host ] || '0.0.0.0' port = opts [ :port ] || '8181' web_app = opts [ :app ] dispatch = Rack :: Builder . app do map '/' do run web_app end end unless [ 'thin' , 'hatetepe' , 'goliath' ] . include? server raise "Need an EM webserver, but #{server} isn't" end Rack :: Server . start ( { app : dispatch , server : server , Host : host , Port : port , signals : false , } ) end end
This example shows you how to embed Sinatra into your EventMachine
application.
This example shows you how to embed Sinatra into your EventMachine application .
# Start the reactor # define some defaults for our app # create a base-mapping that our application will set at. If I # have the following routes: # #   get '/hello' do #     'hello!' #   end # #   get '/goodbye' do #     'see ya later!' #   end # # Then I will get the following: # #   mapping: '/' #   routes: #     /hello #     /goodbye # #   mapping: '/api' #   routes: #     /api/hello #     /api/goodbye # NOTE that we have to use an EM-compatible web-server. There # might be more, but these are some that are currently available. # Start the web server. Note that you are free to run other tasks # within your EM instance.
opts
<not_specific>