Sha256: d6466f77149585380bf7d4ddb25125047237c6afd333c9eb4392133e5b2601ab

Contents?: true

Size: 991 Bytes

Versions: 1

Compression:

Stored size: 991 Bytes

Contents

require 'webrick'
require 'launchy'

module ScmsServer
	include WEBrick

	def ScmsServer.start(root_document, port, hostname="localhost")

		puts "Starting server: http://#{hostname}:#{port}"
		#:BindAddress
		server = HTTPServer.new(
			:DocumentRoot => root_document,
			:Port => port, 
			:BindAddress => hostname
		)

		mime_types_file = File.expand_path('../../assets/mime.types', File.dirname(__FILE__))
		WEBrick::HTTPUtils::load_mime_types(mime_types_file)

		trap("INT"){ 
		  puts "Closed http server"
		  server.shutdown
		  exit!
		}

		uri = "http://#{hostname}:#{port}"
		Launchy.open( uri ) do |exception|
		  puts "Attempted to open #{uri} and failed because #{exception}"
		end

		begin
			server.start
		rescue SystemExit, Interrupt
			puts "Closing web brick"
			server.start
		rescue StandardError => e
			puts "StandardError"
			server.shutdown
		rescue Exception => e
			puts "scms-server exception"
			rais e
		end
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scms-3.0.0 lib/scms/scms-httpserver.rb