Sha256: 3ed59dd50cb297f69efb26dd1f91ad2afa85db8621cfec7a01c8b61fa20f6d15

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

require 'sinatra'

module Uki
  class Server
    ##
    # Host string.
    
    attr_reader :host
    
    ##
    # Port number.
    
    attr_reader :port
    
    
    def initialize hoststr
      @host, @port  = (hoststr || 'localhost').split(':')
      @port ||= 21119 # 21 u, 11 k, 9 i
    end
    
    def start!
      host, port = @host, @port # otherwise sinatra host and port will hide Server methods
      Sinatra::Application.class_eval do
        begin
          $stderr.puts 'Started uki server at http://%s:%d' % [host, port.to_i]
          detect_rack_handler.run self, :Host => host, :Port => port do |server|
            trap 'INT' do
              server.respond_to?(:stop!) ? server.stop! : server.stop
            end
          end
        rescue Errno::EADDRINUSE
          raise "Port #{port} already in use"
        rescue Errno::EACCES
          raise "Permission Denied on port #{port}"
        end
      end
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uki-1.1.4 lib/uki/server.rb