Run with WEBrick

This commit is contained in:
Alex Kotov 2023-05-02 18:13:20 +04:00
parent 3d46928867
commit 5fb5be3375
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 35 additions and 2 deletions

View file

@ -43,6 +43,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.7'
spec.add_runtime_dependency 'sinatra', '~> 3.0', '>= 3.0.6'
spec.add_runtime_dependency 'webrick', '~> 1.8', '>= 1.8.1'
spec.add_development_dependency 'pry', '~> 0.14'
spec.add_development_dependency 'rake', '~> 13.0'

View file

@ -2,6 +2,7 @@
require 'rack'
require 'sinatra/base'
require 'webrick'
require_relative 'diversipub/main'
require_relative 'diversipub/rack_app'

View file

@ -24,13 +24,15 @@ module Diversipub
p stdin
p stdout
p stderr
sleep 1 while @running
webrick_thread.join
true
end
def finish
puts 'finishing'
@running = false
webrick.shutdown
nil
end
private
@ -50,5 +52,30 @@ module Diversipub
[String(key).freeze, String(value).freeze]
end.freeze
end
def webrick_thread
@webrick_thread ||= Thread.start { webrick.start }
end
def webrick
@webrick ||= WEBrick::HTTPServer.new(webrick_options).tap do |webrick|
webrick.mount '/', Rack::Handler::WEBrick, rack_app
end
end
def webrick_options
@webrick_options ||= {
BindAddress: 'localhost',
Port: 8080,
}.freeze
end
def rack_app
@rack_app ||= RackApp.new sinatra_app
end
def sinatra_app
@sinatra_app ||= SinatraApp.new self
end
end
end

View file

@ -19,5 +19,9 @@ module Diversipub
# Disable default Sinatra servers & middleware.
alias new new!
end
get '/' do
'Hello, World!'
end
end
end