pikesley/uncle-clive

View on GitHub
lib/uncle_clive/racks.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'rack/conneg'
require 'rack/tracker'

module UncleClive
  class App < Sinatra::Base
    set :public_folder, 'public'
    set :views, 'views'

    if CONFIG['google-analytics-tag']
      use Rack::Tracker do
        handler :google_analytics, { tracker: CONFIG['google-analytics-tag'] }
      end
    end

    use Rack::Conneg do |conneg|
      conneg.set :accept_all_extensions, true
      conneg.set :fallback, :html
      conneg.ignore_contents_of 'public'
      conneg.provide [
        :html,
        :json,
        :svg,
        :text
      ]
    end

    before do
      if negotiated?
        content_type negotiated_type
      end
    end
  end
end