Class: Gitem::Server
- Inherits:
-
Object
- Object
- Gitem::Server
- Defined in:
- lib/gitem/server.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(root, port = 8000) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
Constructor Details
#initialize(root, port = 8000) ⇒ Server
Returns a new instance of Server.
7 8 9 10 11 |
# File 'lib/gitem/server.rb', line 7 def initialize(root, port = 8000) @root = root @port = port @url = "http://localhost:#{port}" end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/gitem/server.rb', line 5 def url @url end |
Instance Method Details
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gitem/server.rb', line 13 def start puts "🌐 Server running at #{@url}" puts " Press Ctrl+C to stop\n\n" server = WEBrick::HTTPServer.new( Port: @port, DocumentRoot: @root, Logger: WEBrick::Log.new($stderr, WEBrick::Log::WARN), AccessLog: [] ) trap("INT") { server.shutdown } trap("TERM") { server.shutdown } server.start end |