Fix #57. Clean URLs clean even if there's a directory

Having join/developer.html, join.html, and clean_urls set now allows
join.html to be resolved when hitting /join/
parent fb0a4954
...@@ -46,7 +46,7 @@ http { ...@@ -46,7 +46,7 @@ http {
mruby_post_read_handler /app/bin/config/lib/ngx_mruby/headers.rb cache; mruby_post_read_handler /app/bin/config/lib/ngx_mruby/headers.rb cache;
mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache; mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache;
<% if clean_urls %> <% if clean_urls %>
try_files $uri $uri/ $uri.html $fallback; try_files $uri.html $uri $uri/ $fallback;
<% else %> <% else %>
try_files $uri $uri/ $fallback; try_files $uri $uri/ $fallback;
<% end %> <% end %>
...@@ -70,7 +70,7 @@ http { ...@@ -70,7 +70,7 @@ http {
mruby_set $path /app/bin/config/lib/ngx_mruby/routes_path.rb cache; mruby_set $path /app/bin/config/lib/ngx_mruby/routes_path.rb cache;
mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache; mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache;
<% if clean_urls %> <% if clean_urls %>
try_files $uri $uri/ /$uri.html $path $fallback; try_files $uri.html $uri $uri/ $path $fallback;
<% else %> <% else %>
try_files $uri $path $fallback; try_files $uri $path $fallback;
<% end %> <% end %>
......
...@@ -68,6 +68,23 @@ RSpec.describe "Simple" do ...@@ -68,6 +68,23 @@ RSpec.describe "Simple" do
expect(response.body.chomp).to eq("bar") expect(response.body.chomp).to eq("bar")
end end
end end
context "when there is a conflict" do
let(:name) { "clean_urls_conflict" }
it "should be able to handle when a directory and .html file share the same name" do
app.run do
response = app.get("/foo/bar")
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("bar")
response = app.get("/foo")
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("foobar")
end
end
end
end end
describe "routes" do describe "routes" do
...@@ -548,9 +565,13 @@ STATIC_JSON ...@@ -548,9 +565,13 @@ STATIC_JSON
expect(response.code).to eq("302") expect(response.code).to eq("302")
expect(app.get(response["location"]).body.chomp).to eq("goodbye") expect(app.get(response["location"]).body.chomp).to eq("goodbye")
response = app.get("/foo") response = app.get("/hello")
expect(response.code).to eq("200") expect(response.code).to eq("200")
expect(response.body.chomp).to eq("hello world") expect(response.body.chomp).to eq("hello world")
response = app.get("/foo")
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("foo")
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment