1
0
Fork 0
diversipub/lib/diversipub/rack_app.rb

48 lines
963 B
Ruby

# frozen_string_literal: true
module Diversipub
##
# Rack web application.
#
class RackApp
def initialize(main)
@main = main
end
def call(env)
to_app.call env
end
def to_app
@to_app ||= builder.to_app
end
private
def builder
@builder ||= Rack::Builder.new.tap do |builder|
builder.use Rack::Head
builder.use Rack::ShowExceptions
builder.use Rack::ShowStatus
builder.use Rack::ContentLength
builder.use Rack::Protection, except: %i[session_hijacking]
builder.use Rack::Static, **rack_static_kwargs
builder.run rest
end
end
def rack_static_kwargs
@rack_static_kwargs ||= {
cascade: true,
index: 'index.html',
root: File.expand_path('../website/build').freeze,
urls: [''].freeze,
}.freeze
end
def rest
@rest ||= ->(_) { [200, {}, ['Hello, World!']] }
end
end
end