Last active
January 29, 2021 07:03
-
-
Save leastbad/f128233ee15171eec7ea8587d95b736a to your computer and use it in GitHub Desktop.
Rails relative URL middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map ActionController::Base.config.relative_url_root || "/" do | |
| run FooApp::Application | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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