1
0
Fork 0

Remove Sinatra

This commit is contained in:
Alex Kotov 2023-05-10 00:47:15 +04:00
parent 7d66cef6bc
commit cfef4c16b2
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
6 changed files with 10 additions and 42 deletions

View File

@ -46,7 +46,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'puma', '~> 6.2', '>= 6.2.2'
spec.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.7'
spec.add_runtime_dependency 'rack-protection', '~> 3.0', '>= 3.0.6'
spec.add_runtime_dependency 'sinatra', '~> 3.0', '>= 3.0.6'
spec.add_development_dependency 'bundler', '~> 2.4'
spec.add_development_dependency 'pry', '~> 0.14'

View File

@ -38,9 +38,6 @@ ENV.delete 'RACK_MULTIPART_FILE_LIMIT'
ENV.delete 'RACK_MULTIPART_PART_LIMIT'
ENV.delete 'RACK_MULTIPART_TOTAL_PART_LIMIT'
# Clean Sinatra ENVs
ENV.delete 'PORT'
# Freeze well-known constants
ARGV.each(&:freeze).freeze
ENV.each_key(&:freeze).each_value(&:freeze) # ENV itself can't be frozen

View File

@ -14,7 +14,7 @@ require 'pathname'
require 'puma'
require 'rack'
require 'rack/handler/puma'
require 'sinatra/base'
require 'rack/protection'
################
# Own requires #
@ -23,7 +23,6 @@ require 'sinatra/base'
require_relative 'diversipub/main'
require_relative 'diversipub/puma_task'
require_relative 'diversipub/rack_app'
require_relative 'diversipub/sinatra_app'
require_relative 'diversipub/version'
##

View File

@ -64,11 +64,7 @@ module Diversipub
end
def rack_app
@rack_app ||= RackApp.new sinatra_app
end
def sinatra_app
@sinatra_app ||= SinatraApp.new @main
@rack_app ||= RackApp.new @main
end
end
end

View File

@ -5,8 +5,8 @@ module Diversipub
# Rack web application.
#
class RackApp
def initialize(sinatra_app)
@sinatra_app = sinatra_app
def initialize(main)
@main = main
end
def call(env)
@ -23,8 +23,8 @@ module Diversipub
@builder ||= Rack::Builder.new.tap do |builder|
builder.use Rack::Head
builder.use Rack::Static, **rack_static_kwargs
builder.use Rack::Protection
builder.run @sinatra_app
builder.use Rack::Protection, except: %i[session_hijacking]
builder.run rest
end
end
@ -36,5 +36,9 @@ module Diversipub
urls: [''].freeze,
}.freeze
end
def rest
@rest ||= ->(_) { [200, {}, ['Hello, World!']] }
end
end
end

View File

@ -1,27 +0,0 @@
# frozen_string_literal: true
module Diversipub
##
# Sinatra web application.
#
class SinatraApp < Sinatra::Base
set :environment, :production
set :root, File.expand_path('../..', __dir__).freeze
set :views, nil
set :public_folder, nil
def initialize(main)
super()
@main = main
end
class << self
# Disable default Sinatra servers & middleware.
alias new new!
end
get '/index.html' do
redirect 'ru/index.html'
end
end
end