Class: Sandals::Server
- Inherits:
-
Object
- Object
- Sandals::Server
- Defined in:
- lib/sandals/server.rb
Constant Summary collapse
- SESSION_COOKIE =
"sandals_session"- MAX_UPLOAD_SIZE =
10 * 1024 * 1024
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(application, port: 0, reload_path: nil) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
- #url ⇒ Object
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
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/sandals/server.rb', line 12 def port @port end |
Instance Method Details
#start ⇒ Object
29 30 31 |
# File 'lib/sandals/server.rb', line 29 def start @server.start end |
#stop ⇒ Object
33 34 35 |
# File 'lib/sandals/server.rb', line 33 def stop @server.shutdown end |
#url ⇒ Object
37 38 39 |
# File 'lib/sandals/server.rb', line 37 def url "http://127.0.0.1:#{port}" end |