Class: Yarrow::Server

Inherits:
Object
  • Object
show all
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

Methods included from Configurable

#config

Constructor Details

#initializeServer

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

#appYarrow::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.

Returns:

  • (Yarrow::Server::StaticFiles)


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

#runObject

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(run_options[:server])
  server.run(app, run_options)
end