Sha256: 0c194db0b41ac457db0262c504172622d898e132f00fb14f69a57ab0ea2137d8

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

require 'rubygems'
require 'rack'
require 'rackup'
require 'webrick'

class SampleApp

  def self.start(host, port)
    Rackup::Handler::WEBrick.run new,
                               :Host => host,
                               :Port => port,
                               :Logger => ::WEBrick::Log.new(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null'),
                               :AccessLog => [nil, nil]
  end

  def initialize
    @public = File.expand_path("../public", __FILE__)
  end

  def call(env)
    req = Rack::Request.new(env)

    case req.path
    when "/"
      [200, {}, ["Sample Application"]]
    when "/compute"
      sleep 5
      resp = eval(req.params['calculator-expression']).to_s
      [200, {}, [resp]]
    else
      @public.call(env)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
druid-s-1.0.0 features/sample-app/sample_app.rb