diff --git a/lib/Mojolicious/Static.pm b/lib/Mojolicious/Static.pm index a3745445f2..6d295838b9 100644 --- a/lib/Mojolicious/Static.pm +++ b/lib/Mojolicious/Static.pm @@ -11,10 +11,21 @@ use Mojo::Util 'md5_sum'; has classes => sub { ['main'] }; has paths => sub { [] }; - -# Bundled files -my $PUBLIC = Mojo::Home->new(Mojo::Home->new->mojo_lib_dir) - ->child('Mojolicious', 'resources', 'public'); +has bundled => sub { + + # Bundled files + my $public = Mojo::Home->new(Mojo::Home->new->mojo_lib_dir) + ->child('Mojolicious', 'resources', 'public'); + return { + @{ + $public->list_tree->map( + sub { + $_->to_rel($public)->to_string, $_->realpath; + } + ) + } + }; +}; sub dispatch { my ($self, $c) = @_; @@ -48,8 +59,9 @@ sub file { # Search DATA if (my $asset = $self->_get_data_file($rel)) { return $asset } - # Search bundled files - return $self->_get_file(path($PUBLIC, split('/', $rel))->to_string); + # Search bundled or special files + return undef unless exists $self->bundled->{$rel}; + return $self->_get_file($self->bundled->{$rel}); } sub is_fresh { diff --git a/t/mojolicious/production_app.t b/t/mojolicious/production_app.t index 72da8b0ca2..97e248084e 100644 --- a/t/mojolicious/production_app.t +++ b/t/mojolicious/production_app.t @@ -33,6 +33,9 @@ is $t->app, $t->app->commands->app, 'applications are equal'; is $t->app->static->file('hello.txt')->slurp, "Hello Mojo from a static file!\n", 'right content'; is $t->app->static->file('does_not_exist.html'), undef, 'no file'; +isnt $t->app->static->file('mojo/jquery/jquery.js'), undef, 'find built-in jQuery'; +delete $t->app->static->bundled->{'mojo/jquery/jquery.js'}; +is $t->app->static->file('mojo/jquery/jquery.js'), undef, 'suppress built-in jQuery'; is $t->app->moniker, 'mojolicious_test', 'right moniker'; # Default namespaces