This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/lib/reroute_middleware.rb

28 lines
752 B
Ruby

class RerouteMiddleware
def initialize(app)
@app = app
end
def call(env)
#Rails.logger.debug env.to_yaml
return @app.call(env) if env['REQUEST_URI'] =~ /^\/admin/
env['REQUEST_URI'] =~ /^\/([0-9a-zA-Z\-_\/]*)/
parsed_entry_name = $1
entry = Item.find_by_full_name( parsed_entry_name )
case entry.type.to_s
when 'Component' :
env['REQUEST_URI'] = env['REQUEST_URI'].sub!(parsed_entry_name, entry.engine_name)
env['QUERY_STRING'] = (env['QUERY_STRING'].blank?)? "entry_name=#{parsed_entry_name}" : "entry_name=#{parsed_entry_name}&#{env['QUERY_STRING']}"
when 'Link' :
return [301, {'Location' => entry.url }, ['See Ya!']]
end
@app.call(env)
end
end