make zeitwerk happy
This commit is contained in:
parent
ec0b5d6c3d
commit
989d0db926
|
@ -1,8 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "boot"
|
require_relative "boot"
|
||||||
require_relative "../lib/middleware/custom_static_middleware"
|
require_relative "../lib/middleware/custom_static"
|
||||||
require_relative "../lib/middleware/dev_host_middleware"
|
require_relative "../lib/middleware/dev_host"
|
||||||
|
|
||||||
require "rails/all"
|
require "rails/all"
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ module Websites
|
||||||
config.action_controller.action_on_unpermitted_parameters = :raise
|
config.action_controller.action_on_unpermitted_parameters = :raise
|
||||||
config.action_dispatch.default_headers.clear
|
config.action_dispatch.default_headers.clear
|
||||||
|
|
||||||
config.middleware.insert_before(0, DevHostMiddleware) if Rails.env.development?
|
config.middleware.insert_before(0, Middleware::DevHost) if Rails.env.development?
|
||||||
config.middleware.insert_before(ActionDispatch::Static, CustomStaticMiddleware, {
|
config.middleware.insert_before(ActionDispatch::Static, Middleware::CustomStatic, {
|
||||||
/^i\.furry\.cool/ => "/furry.cool/images",
|
/^i\.furry\.cool/ => "/furry.cool/images",
|
||||||
/^i\.maidboye\.cafe/ => "/maidboye.cafe/images",
|
/^i\.maidboye\.cafe/ => "/maidboye.cafe/images",
|
||||||
%r{^maidboye\.cafe/images} => "/maidboye.cafe",
|
%r{^maidboye\.cafe/images} => "/maidboye.cafe",
|
||||||
|
|
32
lib/middleware/custom_static.rb
Normal file
32
lib/middleware/custom_static.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Middleware
|
||||||
|
class CustomStatic
|
||||||
|
def initialize(app, domain_map)
|
||||||
|
@app = app
|
||||||
|
@domain_map = domain_map
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
request = Rack::Request.new(env)
|
||||||
|
host = request.host
|
||||||
|
|
||||||
|
if (target_path = find_mapped_path(host, request.path))
|
||||||
|
env["PATH_INFO"] = target_path
|
||||||
|
end
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_mapped_path(host, path)
|
||||||
|
@domain_map.each do |domain_pattern, subdirectory|
|
||||||
|
matcher = "#{host}#{path}"
|
||||||
|
return "#{subdirectory}#{path}" if matcher.match?(domain_pattern)
|
||||||
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,30 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class CustomStaticMiddleware
|
|
||||||
def initialize(app, domain_map)
|
|
||||||
@app = app
|
|
||||||
@domain_map = domain_map
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
request = Rack::Request.new(env)
|
|
||||||
host = request.host
|
|
||||||
|
|
||||||
if (target_path = find_mapped_path(host, request.path))
|
|
||||||
env["PATH_INFO"] = target_path
|
|
||||||
end
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def find_mapped_path(host, path)
|
|
||||||
@domain_map.each do |domain_pattern, subdirectory|
|
|
||||||
matcher = "#{host}#{path}"
|
|
||||||
return "#{subdirectory}#{path}" if matcher.match?(domain_pattern)
|
|
||||||
end
|
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
16
lib/middleware/dev_host.rb
Normal file
16
lib/middleware/dev_host.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
module Middleware
|
||||||
|
class DevHost
|
||||||
|
def initialize(app)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
request = Rack::Request.new(env)
|
||||||
|
domain = request.params["domain"]
|
||||||
|
|
||||||
|
env["HTTP_HOST"] = domain if Rails.env.development? && domain
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,14 +0,0 @@
|
||||||
class DevHostMiddleware
|
|
||||||
def initialize(app)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
request = Rack::Request.new(env)
|
|
||||||
domain = request.params["domain"]
|
|
||||||
|
|
||||||
env["HTTP_HOST"] = domain if Rails.env.development? && domain
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user