diff --git a/middleman-core/lib/middleman-core/cli/build.rb b/middleman-core/lib/middleman-core/cli/build.rb index 2d9e0ded..9f7f6024 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -99,10 +99,7 @@ module Middleman::Cli # # @return [Rack::Test::Session] def shared_rack - @_shared_rack ||= begin - mock = ::Rack::MockSession.new(shared_server.to_rack_app) - ::Rack::Test::Session.new(mock) - end + @_shared_rack ||= ::Rack::Test::Session.new(shared_server.to_rack_app) end # Set the root path to the Middleman::Application's root diff --git a/middleman-core/lib/middleman-core/core_extensions/request.rb b/middleman-core/lib/middleman-core/core_extensions/request.rb index 9f750e16..237eeb2e 100644 --- a/middleman-core/lib/middleman-core/core_extensions/request.rb +++ b/middleman-core/lib/middleman-core/core_extensions/request.rb @@ -37,7 +37,6 @@ module Middleman # @private def reset! @app = nil - @prototype = nil end # The shared Rack instance being build @@ -94,7 +93,8 @@ module Middleman # @private # @return [Rack::Builder] def prototype - @prototype ||= to_rack_app + reset! + to_rack_app end # Call prototype, use in config.ru diff --git a/middleman-more/features/asset_hash.feature b/middleman-more/features/asset_hash.feature index b5945ba5..622e09ba 100644 --- a/middleman-more/features/asset_hash.feature +++ b/middleman-more/features/asset_hash.feature @@ -99,3 +99,8 @@ Feature: Assets get a file hash appended to their and references to them are upd Given the Server is running at "asset-hash-app" When I go to "/" Then I should see 'href="stylesheets/site-5770af52.css' + When I go to "stylesheets/site-5770af52.css" + Then I should see 'background-image' + Then I should see 'Added by Rack filter' + When I go to "stylesheets/site-50eaa978.css" + Then I should see 'Not Found' diff --git a/middleman-more/lib/middleman-more/extensions/asset_hash.rb b/middleman-more/lib/middleman-more/extensions/asset_hash.rb index 7d03535c..6605c754 100644 --- a/middleman-more/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-more/lib/middleman-more/extensions/asset_hash.rb @@ -36,7 +36,12 @@ module Middleman next if @ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) } if resource.template? # if it's a template, render it out - digest = Digest::SHA1.hexdigest(resource.render)[0..7] + # Render through the Rack interface so middleware and mounted apps get a shot + rack_client = ::Rack::Test::Session.new(@app.class) + response = rack_client.get(URI.escape(resource.destination_path), {}, { "bypass_asset_hash" => true }) + raise "#{resource.path} should be in the sitemap!" unless response.status == 200 + + digest = Digest::SHA1.hexdigest(response.body)[0..7] else # if it's a static file, just hash it digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7] end @@ -60,6 +65,9 @@ module Middleman def call(env) status, headers, response = @rack_app.call(env) + # We don't want to use this middleware when rendering files to figure out their hash! + return [status, headers, response] if env["bypass_asset_hash"] + path = @middleman_app.full_path(env["PATH_INFO"]) dirpath = Pathname.new(File.dirname(path))