Sha256: ffb87441f2d11763b95a0ff910ca2f702edf4114c01672e807e0466172d4e5c6

Contents?: true

Size: 911 Bytes

Versions: 3

Compression:

Stored size: 911 Bytes

Contents

# encoding: utf-8

require 'reel'
require 'reel/rack'

module Adhearsion
  # @private
  class HTTPServer
    def self.start
      config = Adhearsion.config.core.http

      return unless config.enable

      rackup = File.join(Adhearsion.root, config.rackup)
      unless File.exists?(rackup)
        logger.error "Cannot start HTTP server because the Rack configuration does not exist at #{rackup}"
        return
      end

      app, options = ::Rack::Builder.parse_file rackup
      options = {
        Host: config.host,
        Port: config.port,
      }.merge(options)

      app = Rack::CommonLogger.new(app, logger)

      logger.info "Starting HTTP server listening on #{config.host}:#{config.port}"

      supervisor = ::Reel::Rack::Server.supervise_as(:ahn_http_server, app, options)

      Adhearsion::Events.register_callback :shutdown do
        supervisor.terminate
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-3.0.0.rc1 lib/adhearsion/http_server.rb
adhearsion-3.0.0.beta2 lib/adhearsion/http_server.rb
adhearsion-3.0.0.beta1 lib/adhearsion/http_server.rb