Class: RailsMarkup::HttpServer
- Inherits:
-
Object
- Object
- RailsMarkup::HttpServer
- Defined in:
- lib/rails_markup/http_server.rb
Overview
HTTP server providing REST API + SSE for the browser-side annotation controller. Wire-compatible with Agentation's HTTP API.
Instance Attribute Summary collapse
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(store:, port: 4747, bind: "127.0.0.1", logger: nil) ⇒ HttpServer
constructor
A new instance of HttpServer.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(store:, port: 4747, bind: "127.0.0.1", logger: nil) ⇒ HttpServer
Returns a new instance of HttpServer.
16 17 18 19 20 21 |
# File 'lib/rails_markup/http_server.rb', line 16 def initialize(store:, port: 4747, bind: "127.0.0.1", logger: nil) @store = store @port = port @bind = bind @logger = logger || WEBrick::Log.new($stderr, WEBrick::Log::WARN) end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
14 15 16 |
# File 'lib/rails_markup/http_server.rb', line 14 def bind @bind end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/rails_markup/http_server.rb', line 12 def port @port end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
12 13 14 |
# File 'lib/rails_markup/http_server.rb', line 12 def store @store end |
Instance Method Details
#shutdown ⇒ Object
43 44 45 |
# File 'lib/rails_markup/http_server.rb', line 43 def shutdown @server&.shutdown end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_markup/http_server.rb', line 23 def start # Bind to loopback by default — this store server is unauthenticated, so # binding to 0.0.0.0 would expose it to the whole LAN. Pass bind: "0.0.0.0" # (bin/markup server --host 0.0.0.0) to deliberately expose it. @server = WEBrick::HTTPServer.new( Port: @port, BindAddress: @bind, Logger: @logger, AccessLog: [], DoNotReverseLookup: true ) @server.mount("/", CorsServlet, @store) trap("INT") { @server.shutdown } trap("TERM") { @server.shutdown } @server.start end |