Sha256: 08bc76b15d89e5352fa2e43ab0d10741a16f240651333c72ec7bef288a061093

Contents?: true

Size: 1.21 KB

Versions: 32

Compression:

Stored size: 1.21 KB

Contents

require 'webrick'
require 'launchy'
require "scms/scms-utils.rb"

module ScmsServer
	include WEBrick

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

		portopen = ScmsUtils.port_open? hostname, port
		puts "Port Open: #{portopen}"

		if !portopen
			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!
			}
		else
			puts "Server already running on port: #{port}"
		end

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

		if !portopen
			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

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
scms-4.5.1 lib/scms/scms-httpserver.rb
scms-4.5.0 lib/scms/scms-httpserver.rb
scms-4.4.9 lib/scms/scms-httpserver.rb
scms-4.4.8 lib/scms/scms-httpserver.rb
scms-4.4.6 lib/scms/scms-httpserver.rb
scms-4.4.5 lib/scms/scms-httpserver.rb
scms-4.4.4 lib/scms/scms-httpserver.rb
scms-4.4.3 lib/scms/scms-httpserver.rb
scms-4.4.2 lib/scms/scms-httpserver.rb
scms-4.4.1 lib/scms/scms-httpserver.rb
scms-4.4.0 lib/scms/scms-httpserver.rb
scms-4.3.0 lib/scms/scms-httpserver.rb
scms-4.2.6 lib/scms/scms-httpserver.rb
scms-4.2.5 lib/scms/scms-httpserver.rb
scms-4.2.4 lib/scms/scms-httpserver.rb
scms-4.2.3 lib/scms/scms-httpserver.rb
scms-4.2.2 lib/scms/scms-httpserver.rb
scms-4.2.0 lib/scms/scms-httpserver.rb
scms-4.1.2 lib/scms/scms-httpserver.rb
scms-4.1.1 lib/scms/scms-httpserver.rb