History

Add trailing slash redirections

Fixes #13.

Thibaut committed 13 years ago

Commit dec2f5a1 parent 5ed77221 file · +12 −5Browse files

Unified · Split

lib/app.rb+12−5
@@ -118,15 +118,22 @@ class App < Sinatra::Application · 117 unmodified lines
118 end118 end
119 end119 end
120 120
121 get %r{\A/(.+?)(?=\-|/)} do |doc|
122 return 404 unless @doc = settings.docs[doc]
123 erb :other
124 end
125
126 get '/ping' do121 get '/ping' do
127 200122 200
128 end123 end
129 124
125 get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
126 return 404 unless @doc = settings.docs[doc]
127
128 if !rest && !slash
129 redirect "/#{doc}#{type}/"
130 elsif rest && rest.end_with?('/')
131 redirect "#{doc}#{type}#{slash}#{rest[0...-1]}"
132 else
133 erb :other
134 end
135 end
136
130 not_found do137 not_found do
131 send_file File.join(settings.public_folder, '404.html'), status: status138 send_file File.join(settings.public_folder, '404.html'), status: status
132 end139 end