Class: Nonnative::HTTPServer

Inherits:
Server show all
Defined in:
lib/nonnative/http_server.rb

Overview

Puma-based HTTP server runner.

This is a convenience server implementation for running a Rack/Sinatra application in-process under Nonnative’s server lifecycle. It binds to the configured proxy host/port (so it works consistently with proxy configuration) and uses Puma for HTTP serving.

The server is started and stopped by Server via #perform_start / #perform_stop.

Note: In YAML configuration you typically set class to a concrete subclass that calls ‘super(app, service)`.

Examples:

Running a Sinatra app

app = Sinatra.new do
  get('/hello') { 'Hello World!' }
end

Nonnative.configure do |config|
  config.server do |s|
    s.name = 'http'
    s.klass = ->(service) { Nonnative::HTTPServer.new(app, service) }
    s.timeout = 2
    s.host = '127.0.0.1'
    s.port = 4567
    s.log = 'http.log'
  end
end

See Also:

Direct Known Subclasses

HTTPProxyServer

Instance Attribute Summary

Attributes inherited from Runner

#proxy

Instance Method Summary collapse

Methods inherited from Server

#start, #stop

Methods inherited from Runner

#name

Constructor Details

#initialize(app, service) ⇒ HTTPServer

Creates a Puma server for the given Rack app and runner configuration.



36
37
38
39
40
41
42
43
44
45
# File 'lib/nonnative/http_server.rb', line 36

def initialize(app, service)
  log = File.open(service.log, 'a')
  options = {
    log_writer: Puma::LogWriter.new(log, log),
    force_shutdown_after: service.timeout
  }
  @server = Puma::Server.new(app, Puma::Events.new, options)

  super(service)
end