Class: Wsv::Server
- Inherits:
-
Object
- Object
- Wsv::Server
- Defined in:
- lib/wsv/server.rb,
lib/wsv/server/banner.rb,
lib/wsv/server/url_host.rb,
lib/wsv/server/access_log.rb,
lib/wsv/server/connection.rb,
lib/wsv/server/deadline_reader.rb,
lib/wsv/server/browser_launcher.rb,
lib/wsv/server/connection_throttle.rb
Defined Under Namespace
Modules: UrlHost Classes: AccessLog, Banner, BrowserLauncher, Connection, ConnectionThrottle, DeadlineReader, NullAccessLog
Constant Summary collapse
- DEFAULT_READ_TIMEOUT =
10- DEFAULT_MAX_CONNECTIONS =
8
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(host:, port:, root:, out: $stdout, err: $stderr, read_timeout: DEFAULT_READ_TIMEOUT, max_connections: DEFAULT_MAX_CONNECTIONS, tls: nil, spa: false, open: false, cors: false, quiet: false, app: nil) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(host:, port:, root:, out: $stdout, err: $stderr, read_timeout: DEFAULT_READ_TIMEOUT, max_connections: DEFAULT_MAX_CONNECTIONS, tls: nil, spa: false, open: false, cors: false, quiet: false, app: nil) ⇒ Server
Returns a new instance of Server.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wsv/server.rb', line 19 def initialize( host:, port:, root:, out: $stdout, err: $stderr, read_timeout: DEFAULT_READ_TIMEOUT, max_connections: DEFAULT_MAX_CONNECTIONS, tls: nil, spa: false, open: false, cors: false, quiet: false, app: nil ) @host = host @port = port @root = File.realpath(root) @out = out @err = err @read_timeout = read_timeout @tls = tls @ssl_context = tls&.to_ssl_context @open = open @cors = Cors.new if cors @access_log = quiet ? NullAccessLog.new : AccessLog.new(out: out) # `app:` lets callers plug in a custom request handler in place of # the default file server. @app = app || App.new(@root, spa: spa, cors: @cors) @throttle = ConnectionThrottle.new(max: max_connections, err: err) @running = false end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
17 18 19 |
# File 'lib/wsv/server.rb', line 17 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
17 18 19 |
# File 'lib/wsv/server.rb', line 17 def port @port end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
17 18 19 |
# File 'lib/wsv/server.rb', line 17 def root @root end |
Instance Method Details
#start ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wsv/server.rb', line 52 def start @server = TCPServer.new(host, port) @running = true log_startup trap_signals open_in_browser if @open accept_loop ensure close end |
#stop ⇒ Object
63 64 65 66 |
# File 'lib/wsv/server.rb', line 63 def stop @running = false close end |