Skip to content

Instantly share code, notes, and snippets.

@leastbad
Last active January 29, 2021 07:03
Show Gist options
  • Select an option

  • Save leastbad/f128233ee15171eec7ea8587d95b736a to your computer and use it in GitHub Desktop.

Select an option

Save leastbad/f128233ee15171eec7ea8587d95b736a to your computer and use it in GitHub Desktop.
Rails relative URL middleware
config.action_controller.relative_url_root = '/somebaseurl'
config.middleware.use RecodeUrl
class RecodeUrl
def initialize(app, options = {})
@app = app
end
def call(env)
# binding.pry
env['PATH_INFO'] = env['PATH_INFO'].sub('/somebaseurl','/')
@app.call(env)
end
end
map ActionController::Base.config.relative_url_root || "/" do
run FooApp::Application
end
scope (ActionController::Base.config.relative_url_root || "/") do
# all your routes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment