Skip to content

Commit

Permalink
Fix problem with windows file separator
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovanton committed Feb 4, 2016
1 parent 7ce11e3 commit 6fc873b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/hanami/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Static < ::Rack::Static
PATH_INFO = 'PATH_INFO'.freeze
PUBLIC_DIRECTORY = Hanami.public_directory.join('**', '*').to_s.freeze

# @since x.x.x
# @api private
URL_SEPARATOR = '/'.freeze

def initialize(app)
super(app, root: Hanami.public_directory, header_rules: _header_rules)
@sources = _sources_from_applications
Expand All @@ -31,8 +35,9 @@ def call(env)
private

def can_serve(path, original = nil)
file_path = path.gsub(URL_SEPARATOR, ::File::SEPARATOR)
destination = Dir[PUBLIC_DIRECTORY].find do |file|
file.index("public#{path}").to_i > 0
file.index("public#{file_path}").to_i > 0
end

(super(path) || !!destination) && _fresh?(original, destination)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/static_assets/test_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
JS
end

get '/assets/dashboard.js'
get 'assets/dashboard.js'
response.body.must_include 'stale'

sleep 1
Expand Down

0 comments on commit 6fc873b

Please sign in to comment.