Class: Ronin::Web::Server::Base
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Ronin::Web::Server::Base
- Includes:
- Conditions, Helpers, Routing
- Defined in:
- lib/ronin/web/server/base.rb
Overview
The base-class for all Ronin Web Servers. Extends Sinatra::Base with additional routing methods, helper methods and Sinatra conditions.
Routing Methods
- any: registers a route that responds to
GET
,POST
,PUT
,PATCH
,DELETE
andOPTIONS
requests. - default: registers the default route.
- basic_auth: enables Basic-Auth authentication for the whole app.
- redirect: adds a route that simply redirects to another URL.
- file: mounts a file at the given path. a given file.
- directory: mounts a directory at the given path.
- public_dir: mounts a directory at the root.
- vhost: mounts a Rack app for the given vhost.
- mount: mounts a Rack app at the given path.
Helper Methods
- h: escapes HTML entities.
- file: sends a file.
- mime_type_for: returns the MIME type for the file.
- content_type_for: sets the
Content-Type
for the file.
Routing Conditions
- client_ip: filters requests based on their client IP address.
- asn: filters requests by the client IP's ASN number.
- country_code: filters requests by the client IP's ASN country code.
- asn_name: filters requests by the client IP's ASN company/ISP name.
- host: filters requests based on the
Host
header. - referer: filters requests based on
the
Referer
header. - user_agent: filters requests
based on the
User-Agent
header. - browser: filters requests based on
the browser name within the
User-Agent
header. - browser_version: filters
requests based on the browser version within the
User-Agent
header. - device_type: filters requests
based on the device type within the
User-Agent
header. - os: filters requests based on the OS
within the
User-Agent
header. - os_version: filters requests
based on the OS version within the
User-Agent
header.
Examples
require 'ronin/web/server'
class App < Ronin::Web::Server::Base
# mount a file
file '/sitemap.xml', './files/sitemap.xml'
# mount a directory
directory '/downloads/', '/tmp/downloads/'
get '/' do
# renders views/index.erb
erb :index
end
get '/test' do
"raw text here"
end
end
App.run!
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_HOST =
Default interface to run the Web Server on
'0.0.0.0'
- DEFAULT_PORT =
Default port to run the Web Server on
8000
Class Method Summary collapse
-
.run!(options = {}, &block) ⇒ Object
Run the web server.
Methods included from Conditions
Methods included from Helpers
#content_type_for, #mime_type_for
Methods included from Routing
Class Method Details
.run!(options = {}, &block) ⇒ Object
Run the web server.
168 169 170 171 172 173 174 |
# File 'lib/ronin/web/server/base.rb', line 168 def self.run!(={},&block) if [:background] Thread.new() { || super() } else super(,&block) end end |