Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix URLs in "middleman serve"
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Like Rack::TryStatic, but tries each possible URL with the app instead. | ||
class Rack::TryDynamic | ||
def initialize(app, options) | ||
@app = app | ||
@try = ['', *options[:try]] | ||
end | ||
|
||
def call(env) | ||
orig_path = env['PATH_INFO'] | ||
found = nil | ||
@try.each do |path| | ||
resp = @app.call(env.merge!({'PATH_INFO' => orig_path + path})) | ||
break if !(403..405).include?(resp[0]) && found = resp | ||
end | ||
found or @app.call(env.merge!('PATH_INFO' => orig_path)) | ||
end | ||
end |