Class: Sandals::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/sandals/server.rb

Constant Summary collapse

"sandals_session"
MAX_UPLOAD_SIZE =
10 * 1024 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, port: 0, reload_path: nil) ⇒ Server

Returns a new instance of Server.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sandals/server.rb', line 14

def initialize(application, port: 0, reload_path: nil)
  @application_factory = application
  @reloader = CodeReloader.new(reload_path) if reload_path
  @applications = {}
  @applications_mutex = Mutex.new
  @server = WEBrick::HTTPServer.new(
    BindAddress: "127.0.0.1",
    Port: port,
    AccessLog: [],
    Logger: WEBrick::Log.new(File::NULL)
  )
  @port = @server.listeners.first.addr[1]
  @server.mount_proc("/") { |request, response| render(request, response) }
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/sandals/server.rb', line 12

def port
  @port
end

Instance Method Details

#startObject



29
30
31
# File 'lib/sandals/server.rb', line 29

def start
  @server.start
end

#stopObject



33
34
35
# File 'lib/sandals/server.rb', line 33

def stop
  @server.shutdown
end

#urlObject



37
38
39
# File 'lib/sandals/server.rb', line 37

def url
  "http://127.0.0.1:#{port}"
end