Sha256: 03a48ca6ba8b8de9d2cec8a4687cd7938118a0c86ca2274c9a05e9a23869c08c

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

require 'rack/handler'
require 'puma'

module Rack
  module Handler
    module Puma
      DEFAULT_OPTIONS = {
        :Host => '0.0.0.0',
        :Port => 8080,
        :Threads => '0:16',
        :Verbose => false
      }

      def self.run(app, options = {})
        options  = DEFAULT_OPTIONS.merge(options)

        if options[:Verbose]
          app = Rack::CommonLogger.new(app, STDOUT)
        end

        server   = ::Puma::Server.new(app)
        min, max = options[:Threads].split(':', 2)

        puts "Puma #{::Puma::Const::PUMA_VERSION} starting..."
        puts "* Min threads: #{min}, max threads: #{max}"
        puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"

        server.add_tcp_listener options[:Host], options[:Port]
        server.min_threads = Integer(min)
        server.max_threads = Integer(max)
        yield server if block_given?

        server.run.join
      end

      def self.valid_options
        {
          "Host=HOST"       => "Hostname to listen on (default: localhost)",
          "Port=PORT"       => "Port to listen on (default: 8080)",
          "Threads=MIN:MAX" => "min:max threads to use (default 0:16)",
          "Quiet"           => "Don't report each request"
        }
      end
    end

    register :puma, Puma
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puma-0.9.5-java lib/rack/handler/puma.rb
puma-0.9.5 lib/rack/handler/puma.rb
puma-0.9.4-java lib/rack/handler/puma.rb
puma-0.9.4 lib/rack/handler/puma.rb
puma-0.9.3-java lib/rack/handler/puma.rb
puma-0.9.3 lib/rack/handler/puma.rb
puma-0.9.2-java lib/rack/handler/puma.rb
puma-0.9.2 lib/rack/handler/puma.rb