Sha256: 2d6450ce6df6df3fcecaad72cea454b03795b152d7ba40a44c75f241b91af544

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

require "rack/handler"
require "rack/handler/puma"

module Rack
  module Handler
    class Toycol
      def self.run(app, options = {})
        if (child_pid = fork)
          environment  = ENV["RACK_ENV"] || "development"
          default_host = environment == "development" ? "localhost" : "0.0.0.0"

          host = options.delete(:Host) || default_host
          port = options.delete(:Port) || "9292"

          ::Toycol::Proxy.new(host, port).start
          Process.waitpid(child_pid)
        else
          puts "Toycol starts Puma in single mode, listening on unix://#{::Toycol::UNIX_SOCKET_PATH}"
          Rack::Handler::Puma.run(app, **{ Host: ::Toycol::UNIX_SOCKET_PATH, Silent: true })
        end
      end
    end

    register :toycol, Toycol
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toycol-0.1.0 lib/rack/handler/toycol.rb