25 lines
645 B
Ruby
25 lines
645 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'] =~ /^\/([\w]*)/
|
|
parsed_entry_name = $1
|
|
|
|
entry = Page.find_by_name( parsed_entry_name )
|
|
|
|
if entry && entry.component_name
|
|
env['REQUEST_URI'] = env['REQUEST_URI'].sub!(parsed_entry_name, entry.component_name)
|
|
env['QUERY_STRING'] = (env['QUERY_STRING'].blank?)? "entry_name=#{parsed_entry_name}" : "entry_name=#{parsed_entry_name}&#{env['QUERY_STRING']}"
|
|
end
|
|
|
|
@app.call(env)
|
|
end
|
|
|
|
end |