Class: Flapjack::Gateways::Web
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Flapjack::Gateways::Web
- Includes:
- Utility
- Defined in:
- lib/flapjack/gateways/web.rb,
lib/flapjack/gateways/web/middleware/request_timestamp.rb
Defined Under Namespace
Modules: Middleware
Class Method Summary collapse
Methods included from Utility
#hashify, #load_template, #local_timezone, #relative_time_ago, #remove_utc_offset, #stringify, #symbolize, #time_period_in_words, #truncate
Class Method Details
.start ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/flapjack/gateways/web.rb', line 37 def start Flapjack.logger.info "starting web - class" set :show_exceptions, false @show_exceptions = Sinatra::ShowExceptions.new(self) if access_log = (@config && @config['access_log']) unless File.directory?(File.dirname(access_log)) raise "Parent directory for log file #{access_log} doesn't exist" end use Rack::CommonLogger, ::Logger.new(@config['access_log']) end # session's only used for error message display, so session_secret = @config['session_secret'] use Rack::Session::Cookie, :key => 'flapjack.session', :path => '/', :secret => session_secret || SecureRandom.hex(64) @api_url = @config['api_url'] if @api_url.nil? raise "'api_url' config must contain a Flapjack API instance address" end uri = begin URI(@api_url) rescue URI::InvalidURIError # TODO should we just log and re-raise the exception? raise "'api_url' is not a valid URI (#{@api_url})" end unless ['http', 'https'].include?(uri.scheme) raise "'api_url' is not a valid http or https URI (#{@api_url})" end unless @api_url.match(/^.*\/$/) Flapjack.logger.info "api_url must end with a trailing '/', setting to '#{@api_url}/'" @api_url = "#{@api_url}/" end Flapjack::Diner.base_uri(@api_url) Flapjack::Diner.logger = Flapjack.logger # constants won't be exposed to eRb scope @default_logo_url = "img/flapjack-2013-notext-transparent-300-300.png" @logo_image_file = nil @logo_image_ext = nil if logo_image_path = @config['logo_image_path'] if File.file?(logo_image_path) @logo_image_file = logo_image_path @logo_image_ext = File.extname(logo_image_path) else Flapjack.logger.error "logo_image_path '#{logo_image_path}'' does not point to a valid file." end end @auto_refresh = (@config['auto_refresh'].respond_to?('to_i') && (@config['auto_refresh'].to_i > 0)) ? @config['auto_refresh'].to_i : false end |