lib/conjur/webserver/server.rb in conjur-asset-ui-1.3.0 vs lib/conjur/webserver/server.rb in conjur-asset-ui-1.3.1

- old
+ new

@@ -28,12 +28,17 @@ require 'conjur/webserver/login' require 'conjur/webserver/authorize' require 'conjur/webserver/api_proxy' require 'conjur/webserver/home' require 'conjur/webserver/conjur_info' - require 'pry' + # Pry is optional + begin + require 'pry' + rescue LoadError + end + sessionid = self.sessionid cookie_options = { secret: SecureRandom.hex(32), expire_after: 24*60*60 } @@ -51,11 +56,11 @@ end map "/api" do api_stack.each{|args| use *args} run Conjur::WebServer::APIProxy.new end - %w(js css fonts images).each do |path| + %w(build js css fonts images).each do |path| map "/#{path}" do run Rack::File.new(File.join(root, path), 'Cache-Control' => 'max-age=0') end end map "/ui" do @@ -76,35 +81,35 @@ # instead we just explicitly set RACK_ENV to "production" on the command call -- this is also bad, but... good enough for now, until we'll fix API configuration logic Conjur.configuration.env Rack::Server.start(options) end - + def open require 'launchy' url = "http://localhost:#{port}/login?sessionid=#{sessionid}" # as launchy sometimes silently fails, we need human-friendly failover - $stderr.puts "If your browser did not opened the UI automatically, point it to #{url}" - Launchy.open(url) + $stderr.puts "If your browser did not opened the UI automatically, point it to #{url}" + Launchy.open(url) unless ENV['DONT_OPEN_IN_BROWSER'] end - + protected - + def port @port ||= find_available_port end DEFAULT_PORT = 42_289 - + def find_available_port begin server = TCPServer.new('127.0.0.1', 0) server.addr[1] ensure server.close if server end end - + def sessionid require 'securerandom' @sessionid ||= SecureRandom.hex(32) end end