Module: Ronin::Web::Server::Routing::ClassMethods
- Defined in:
- lib/ronin/web/server/routing.rb
Overview
Class methods to be added to the application base class.
Instance Method Summary collapse
-
#any(path, conditions = {}) { ... } ⇒ Object
Route any type of request for a given URL pattern.
-
#basic_auth(auth_user, auth_password, realm: 'Restricted') ⇒ Object
Enables Basic-Auth authentication for the entire app.
-
#default { ... } ⇒ Object
Sets the default route.
-
#directory(path, local_dir, conditions = {}) ⇒ Object
Hosts the contents of the directory.
-
#file(path, local_file, conditions = {}) ⇒ Object
Hosts the contents of a file.
-
#mount(dir, app, conditions = {}) ⇒ Object
Routes all requests within a given directory into another Rack application.
-
#public_dir(path, conditions = {}) ⇒ Object
Hosts the static contents within a given directory.
-
#redirect(path, url) ⇒ Object
Sets up a 302 Redirect at the given path.
-
#vhost(host, app, conditions = {}) ⇒ Object
Routes all requests for a given virtual host to another Rack application.
Instance Method Details
#any(path, conditions = {}) { ... } ⇒ Object
Route any type of request for a given URL pattern.
68 69 70 71 72 73 74 75 |
# File 'lib/ronin/web/server/routing.rb', line 68 def any(path,conditions={},&block) get(path,conditions,&block) post(path,conditions,&block) put(path,conditions,&block) patch(path,conditions,&block) delete(path,conditions,&block) (path,conditions,&block) end |
#basic_auth(auth_user, auth_password, realm: 'Restricted') ⇒ Object
Enables Basic-Auth authentication for the entire app.
121 122 123 124 125 |
# File 'lib/ronin/web/server/routing.rb', line 121 def basic_auth(auth_user,auth_password, realm: 'Restricted') use Rack::Auth::Basic, realm do |user,password| user == auth_user && password == auth_password end end |
#default { ... } ⇒ Object
Sets the default route.
99 100 101 102 |
# File 'lib/ronin/web/server/routing.rb', line 99 def default(&block) not_found(&block) return self end |
#directory(path, local_dir, conditions = {}) ⇒ Object
Hosts the contents of the directory.
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/ronin/web/server/routing.rb', line 183 def directory(path,local_dir,conditions={}) path = path.chomp('/') dir = Rack::File.new(local_dir) get("#{path}/*",conditions) do |sub_path| response = dir.call(env.merge('PATH_INFO' => "/#{sub_path}")) if response[0] == 200 then response else pass end end end |
#file(path, local_file, conditions = {}) ⇒ Object
Hosts the contents of a file.
162 163 164 |
# File 'lib/ronin/web/server/routing.rb', line 162 def file(path,local_file,conditions={}) get(path,conditions) { send_file(local_file) } end |
#mount(dir, app, conditions = {}) ⇒ Object
Routes all requests within a given directory into another Rack application.
253 254 255 256 257 258 259 |
# File 'lib/ronin/web/server/routing.rb', line 253 def mount(dir,app,conditions={}) dir = dir.chomp('/') any("#{dir}/?*",conditions) do |sub_path| app.call(env.merge('PATH_INFO' => "/#{sub_path}")) end end |
#public_dir(path, conditions = {}) ⇒ Object
Hosts the static contents within a given directory.
210 211 212 |
# File 'lib/ronin/web/server/routing.rb', line 210 def public_dir(path,conditions={}) directory('/',path,conditions) end |
#redirect(path, url) ⇒ Object
Sets up a 302 Redirect at the given path.
141 142 143 |
# File 'lib/ronin/web/server/routing.rb', line 141 def redirect(path,url) get(path) { redirect(url) } end |
#vhost(host, app, conditions = {}) ⇒ Object
Routes all requests for a given virtual host to another Rack application.
229 230 231 232 233 |
# File 'lib/ronin/web/server/routing.rb', line 229 def vhost(host,app,conditions={}) any('*',conditions.merge(host: host)) do app.call(env) end end |