Run with WEBrick
This commit is contained in:
parent
3d46928867
commit
5fb5be3375
4 changed files with 35 additions and 2 deletions
|
@ -43,6 +43,7 @@ Gem::Specification.new do |spec|
|
||||||
|
|
||||||
spec.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.7'
|
spec.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.7'
|
||||||
spec.add_runtime_dependency 'sinatra', '~> 3.0', '>= 3.0.6'
|
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 'pry', '~> 0.14'
|
||||||
spec.add_development_dependency 'rake', '~> 13.0'
|
spec.add_development_dependency 'rake', '~> 13.0'
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require 'rack'
|
require 'rack'
|
||||||
require 'sinatra/base'
|
require 'sinatra/base'
|
||||||
|
require 'webrick'
|
||||||
|
|
||||||
require_relative 'diversipub/main'
|
require_relative 'diversipub/main'
|
||||||
require_relative 'diversipub/rack_app'
|
require_relative 'diversipub/rack_app'
|
||||||
|
|
|
@ -24,13 +24,15 @@ module Diversipub
|
||||||
p stdin
|
p stdin
|
||||||
p stdout
|
p stdout
|
||||||
p stderr
|
p stderr
|
||||||
sleep 1 while @running
|
|
||||||
|
webrick_thread.join
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def finish
|
def finish
|
||||||
puts 'finishing'
|
puts 'finishing'
|
||||||
@running = false
|
webrick.shutdown
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -50,5 +52,30 @@ module Diversipub
|
||||||
[String(key).freeze, String(value).freeze]
|
[String(key).freeze, String(value).freeze]
|
||||||
end.freeze
|
end.freeze
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,5 +19,9 @@ module Diversipub
|
||||||
# Disable default Sinatra servers & middleware.
|
# Disable default Sinatra servers & middleware.
|
||||||
alias new new!
|
alias new new!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/' do
|
||||||
|
'Hello, World!'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue