al-quran.reflectslight.io/packages/ruby/server/lib/server.rb

50 lines
929 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Server
require "rack"
require_relative "server/puma"
2023-06-29 17:07:24 +02:00
require_relative "server/gzip"
require_relative "server/dir"
def self.app(path)
Rack::Builder.app do
run Server::Dir.new(path)
end
end
def self.for_dir(path, options = {})
new(app(path), options)
end
def initialize(app, options = {})
@app = app
@options = default_options.merge!(options)
@events = Puma::Events.new
@server = Puma::Server.new(@app, @events, @options)
end
2023-06-30 21:14:21 +02:00
def start(block: false)
@server.binder.parse(@options[:binds])
2023-06-30 21:14:21 +02:00
thr = @server.run
block ? thr.join : thr
end
def stop
@server.stop
end
private
def default_options
{
tcp_host: "127.0.0.1",
tcp_port: 7777,
binds: ["tcp://127.0.0.1:7777"],
supported_http_methods: %w[GET HEAD],
min_threads: 1,
max_threads: 5,
workers: 1
}
end
end