make zeitwerk happy

This commit is contained in:
Donovan Daniels 2024-05-03 18:06:08 -05:00
parent ec0b5d6c3d
commit 989d0db926
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
5 changed files with 52 additions and 48 deletions

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
require_relative "boot"
require_relative "../lib/middleware/custom_static_middleware"
require_relative "../lib/middleware/dev_host_middleware"
require_relative "../lib/middleware/custom_static"
require_relative "../lib/middleware/dev_host"
require "rails/all"
@ -36,8 +36,8 @@ module Websites
config.action_controller.action_on_unpermitted_parameters = :raise
config.action_dispatch.default_headers.clear
config.middleware.insert_before(0, DevHostMiddleware) if Rails.env.development?
config.middleware.insert_before(ActionDispatch::Static, CustomStaticMiddleware, {
config.middleware.insert_before(0, Middleware::DevHost) if Rails.env.development?
config.middleware.insert_before(ActionDispatch::Static, Middleware::CustomStatic, {
/^i\.furry\.cool/ => "/furry.cool/images",
/^i\.maidboye\.cafe/ => "/maidboye.cafe/images",
%r{^maidboye\.cafe/images} => "/maidboye.cafe",

View 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

View File

@ -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

View 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

View File

@ -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