class MetalArchives::Middleware::RewriteEndpoint
Dynamically rewrite endpoints
Public Class Methods
rewrite(uri)
click to toggle source
# File lib/metal_archives/middleware/rewrite_endpoint.rb, line 18 def rewrite(uri) return uri unless MetalArchives.config.endpoint new_uri = uri.clone default_uri = URI MetalArchives.config.default_endpoint rewritten_uri = URI MetalArchives.config.endpoint if uri.host == default_uri.host && uri.scheme == default_uri.scheme new_uri.host = rewritten_uri.host new_uri.scheme = rewritten_uri.scheme MetalArchives.config.logger.debug "Rewrite #{uri} to #{new_uri}" end new_uri end
Public Instance Methods
call(env)
click to toggle source
# File lib/metal_archives/middleware/rewrite_endpoint.rb, line 11 def call(env) env[:url] = RewriteEndpoint.rewrite(env[:url]) @app.call env end