今天在看 Rack Gem 的源码时遇到一个问题,百思不得其解。
请问 mount 方法是干嘛用的?
rack / lib / rack / handler / webrick.rb
require 'webrick'
require 'stringio'
require 'rack/content_length'
module Rack
module Handler
class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet
def self.run(app, options={})
environment = ENV['RACK_ENV'] || 'development'
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
options[:BindAddress] = options.delete(:Host) || default_host
options[:Port] ||= 8080
options[:OutputBufferSize] = 5
@server = ::WEBrick::HTTPServer.new(options)
## mount 方法的用途是什么
@server.mount "/", Rack::Handler::WEBrick, app
yield @server if block_given?
@server.start
end
以下是文档的解释,但是我还是不太懂,求高人好形象解释一下,多谢。
mount(dir, servlet, *options) Mounts servlet on dir passing options to the servlet at creation time
# File webrick/httpserver.rb, line 149
def mount(dir, servlet, *options)
@logger.debug(sprintf("%s is mounted on %s.", servlet.inspect, dir))
@mount_tab[dir] = [ servlet, options ]
end