Sha256: 4e37c07ad8b1401601aee1af58d1c4c8df1678045420906089cb7b9782f6325d

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

require 'mimetype_fu'
require 'mime-types'
require 'mime/types'

require 'rack/rewrite'
require 'rack/csrf'
require 'rack/session/moneta'
require 'rack/builder'
require 'rack/lint'
require 'dragonfly/middleware'

require_relative 'middlewares'

if ENV['PROFILER']
  require 'mongo'
  require 'rack-mini-profiler'
end

module Locomotive::Steam
  module Server

    class << self

      def default_middlewares
        server, configuration = self, self.configuration

        -> (stack) {
          use(Rack::Rewrite) { r301 %r{^/(.*)/$}, '/$1' }
          use Middlewares::Favicon

          if configuration.serve_assets
            use ::Rack::Static, {
              root: configuration.asset_path,
              urls: ['/images', '/fonts', '/samples', '/sites']
            }
            use Middlewares::DynamicAssets, {
              root:   configuration.asset_path,
              minify: configuration.minify_assets
            }
          end

          use Dragonfly::Middleware, :steam

          use Rack::Lint
          use Rack::Session::Moneta, configuration.moneta

          use Rack::MiniProfiler if ENV['PROFILER']

          server.steam_middleware_stack.each { |k| use k }
        }
      end

      def steam_middleware_stack
        [
          Middlewares::DefaultEnv,
          Middlewares::Site,
          Middlewares::Logging,
          Middlewares::UrlRedirection,
          Middlewares::Robots,
          Middlewares::Timezone,
          Middlewares::EntrySubmission,
          Middlewares::Locale,
          Middlewares::LocaleRedirection,
          Middlewares::PrivateAccess,
          Middlewares::Path,
          Middlewares::Page,
          Middlewares::Sitemap,
          Middlewares::TemplatizedPage
        ]
      end

      def to_app
        stack = configuration.middleware

        Rack::Builder.new do
          stack.inject(self)

          run Middlewares::Renderer.new(nil)
        end
      end

      def configuration
        Locomotive::Steam.configuration
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
locomotivecms_steam-1.2.1 lib/locomotive/steam/server.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/server.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/server.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/server.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/server.rb