Sha256: 7c82874683f40078c8a1c9579880b0e5328cf75c725b657cd32b54a43667f11a

Contents?: true

Size: 975 Bytes

Versions: 4

Compression:

Stored size: 975 Bytes

Contents

require 'sinatra'
require 'uki/routes'

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

4 entries across 4 versions & 1 rubygems

Version Path
uki-1.1.3 lib/uki/server.rb
uki-1.1.2 lib/uki/server.rb
uki-1.1.1 lib/uki/server.rb
uki-1.1.0 lib/uki/server.rb