Class: Yarrow::Server
- Inherits:
-
Object
- Object
- Yarrow::Server
- Includes:
- Configurable
- Defined in:
- lib/yarrow/server.rb
Overview
Little web server for browsing local files.
Defined Under Namespace
Classes: DirectoryIndex
Instance Method Summary collapse
-
#app ⇒ Yarrow::Server::StaticFiles
Builds a Rack application to serve files in the output directory.
-
#initialize ⇒ Server
constructor
A new instance of Server.
-
#run ⇒ Object
Starts the server.
Methods included from Configurable
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
9 10 11 12 13 |
# File 'lib/yarrow/server.rb', line 9 def initialize if config.server.nil? raise ConfigurationError.new('Missing server entry') end end |
Instance Method Details
#app ⇒ Yarrow::Server::StaticFiles
Builds a Rack application to serve files in the output directory.
If no output directory is specified, defaults to the current working directory.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/yarrow/server.rb', line 44 def app root = docroot index = default_index middleware_stack = middleware_map auto_index = auto_index? mime_type = default_type Rack::Builder.new do middleware_stack.each do |middleware| use middleware end use DirectoryIndex, root: root, index: index app_args = [root, {}].tap { |args| args.push(mime_type) if mime_type } static_app = Rack::File.new(*app_args) if auto_index run Rack::Directory.new(root, static_app) else run static_app end end end |
#run ⇒ Object
Starts the server.
Listens on localhost:8888 unless server.host and server.port are provided in the config.
75 76 77 78 |
# File 'lib/yarrow/server.rb', line 75 def run server = Rack::Handler.get([:server]) server.run(app, ) end |