You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: app.rb
    path of file: ./repos/devdocs/lib
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'bundler/setup'
Bundler.require :app

class App < Sinatra::Application
  Bundler.require environment
  require 'sinatra/cookies'
  require 'tilt/erubi'
  require 'active_support/notifications'

  Rack::Mime::MIME_TYPES['.webapp'] = 'application/x-web-app-manifest+json'

  configure do
    use Rack::SslEnforcer, only_environments: ['production', 'test'], hsts: true, force_secure_cookies: false

    set :sentry_dsn, ENV['SENTRY_DSN']
    set :protection, except: [:frame_options, :xss_header]

    set :root, Pathname.new(File.expand_path('../..', __FILE__))
    set :sprockets, Sprockets::Environment.new(root)

    set :assets_prefix, 'assets'
    set :assets_path, File.join(public_folder, assets_prefix)
    set :assets_manifest_path, File.join(assets_path, 'manifest.json')
    set :assets_compile, %w(*.png docs.js docs.json application.js application.css application-dark.css)

    require 'yajl/json_gem'
    set :docs_prefix, 'docs'
    set :docs_origin, File.join('', docs_prefix)
    set :docs_path, File.join(public_folder, docs_prefix)
    set :docs_manifest_path, File.join(docs_path, 'docs.json')
    set :default_docs, %w(css dom html http javascript)
    set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json')

    set :csp, false

    require 'docs'
    Docs.generate_manifest

    Dir[docs_path, 
    
  def self.parse_docs
    Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|
      doc['full_name'] = doc['name'].dup
      doc['full_name'] << " #{doc['version']}" if doc['version'] && !doc['version'].empty?
      doc['slug_without_version'] = doc['slug'].split('~').first
      [doc['slug'], doc]
    }]
  end

  def self.parse_news
    JSON.parse(File.read(news_path))
  end

  configure :development, :test do
    set :docs, -> { parse_docs }
    set :news, -> { parse_news }
  end

  configure :production do
    set :docs, parse_docs
    set :news, parse_news
  end

  helpers do
    include Sinatra::Cookies
    include Sprockets::Helpers

    def memoized_cookies
      @memoized_cookies ||= cookies.to_hash
    end

    def canonical_origin
      "https://#{request.host_with_port}"
    end

    def browser
      @browser ||= Browser.new(request.user_agent)
    end

    def unsupported_browser?
      browser.ie?
    end

    def docs
      @docs ||= begin
        cookie = memoized_cookies['docs']

        if cookie.nil?
          settings.default_docs
        else
          cookie.split('/')
        end
      end
    end

    def find_doc(slug)
      settings.docs[slug] || begin
        settings.docs.each do |_, doc|
          return doc if doc['slug_without_version'] == slug
        end
        nil
      end
    end

    def user_has_docs?(slug)
      docs.include?(slug) || begin
        slug = "#{slug}~"
        docs.any? { |_slug| _slug.start_with?(slug) }
      end
    end

    def doc_index_urls
      docs.each_with_object [] do |slug, result|
        if doc = settings.docs[slug]
          result << File.join('', settings.docs_prefix, slug, 'index.json') + "?#{doc['mtime']}"
        end
      end
    end

    def doc_index_page?
      @doc && (request.path == "/#{@doc['slug']}/" || request.path == "/#{@doc['slug_without_version']}/")
    end

    def query_string_for_redirection
      request.query_string.empty? ? nil : "?#{request.query_string}"
    end

    def service_worker_asset_urls
      @@service_worker_asset_urls ||= [
        javascript_path('application'),
        stylesheet_path('application'),
        image_path('sprites/docs.png'),
        image_path('sprites/docs@2x.png'),
        asset_path('docs.js'),
        App.production? ? nil : javascript_path('debug'),
      ].compact
    end

    # Returns a cache name for the service worker to use which changes if any of the assets changes
    # When a manifest exist, this name is only created once based on the asset manifest because it never changes without a server restart
    # If a manifest does not exist, it is created every time this method is called because the assets can change while the server is running
    def service_worker_cache_name
      if File.exist?(App.assets_manifest_path)
        if defined?(@@service_worker_cache_name)
          return @@service_worker_cache_name
        end

        digest = Sprockets::Manifest
                   .new(nil, App.assets_manifest_path)
                   .files
                   .values
                   .map {|file| file["digest"]}
                   .join

        return @@service_worker_cache_name ||= Digest::MD5.hexdigest(digest)
      else
        paths = App.sprockets
                  .each_file
                  .to_a
                  .reject {|file| file.start_with?(App.docs_path)}

        return App.sprockets.pack_hexdigest(App.sprockets.files_digest(paths))
      end
    end

    def redirect_via_js(path)
      response.set_cookie :initial_path, value: path, expires: Time.now + 15, path: '/'
      redirect '/', 302
    end

    def supports_js_redirection?
      modern_browser?(browser) && !memoized_cookies.empty?
    end

    # https://github.com/fnando/browser#detecting-modern-browsers
    # https://github.com/fnando/browser/blob/v2.6.1/lib/browser/browser.rb
    # This restores the old browser gem `#modern?` functionality as it was in 2.6.1
    # It's possible this isn't even really needed any longer, these versions are quite old now
    def modern_browser?(browser)
      [
        browser.webkit?,
        browser.firefox? && browser.version.to_i >= 17,
        browser.ie? && browser.version.to_i >= 9 && !browser.compatibility_view?,
        browser.edge? && !browser.compatibility_view?,
        browser.opera? && browser.version.to_i >= 12,
        browser.firefox? && browser.device.tablet? && browser.platform.android? && b.version.to_i >= 14
      ].any?
    end
  end