Class: RailsMarkup::HttpServer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(store:, port: 4747, logger: nil) ⇒ HttpServer

Returns a new instance of HttpServer.



12
13
14
15
16
# File 'lib/rails_markup/http_server.rb', line 12

def initialize(store:, port: 4747, logger: nil)
  @store  = store
  @port   = port
  @logger = logger || WEBrick::Log.new($stderr, WEBrick::Log::WARN)
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/rails_markup/http_server.rb', line 10

def port
  @port
end

#storeObject (readonly)

Returns the value of attribute store.



10
11
12
# File 'lib/rails_markup/http_server.rb', line 10

def store
  @store
end

Instance Method Details

#shutdownObject



34
35
36
# File 'lib/rails_markup/http_server.rb', line 34

def shutdown
  @server&.shutdown
end

#startObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_markup/http_server.rb', line 18

def start
  @server = WEBrick::HTTPServer.new(
    Port: @port,
    Logger: @logger,
    AccessLog: [],
    DoNotReverseLookup: true
  )

  @server.mount("/", CorsServlet, @store)

  trap("INT")  { @server.shutdown }
  trap("TERM") { @server.shutdown }

  @server.start
end