From f2ac574e750616b80f54ce3de7523a9d87b259b3 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Wed, 14 Dec 2016 10:10:57 +0100 Subject: [PATCH 1/2] GH #975: Postpone public_dir calculation: The problem in GH #975 is that we decide what the public_dir should be before we read the configuration, which might give a different public dir. This can be resolved by deciding this later, during the to_app time. The additional problem this exposes is that public_dir created from both DANCER_PUBLIC and "public_dir" configruation option does not take into account the location (app dir). I don't think that's correct. The test shows this in the config.yml file. --- lib/Dancer2/Core/App.pm | 6 +++++- t/issues/gh-975/config.yml | 1 + t/issues/gh-975/gh-975.t | 15 +++++++++++++++ t/issues/gh-975/test_public_dir/test.txt | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 t/issues/gh-975/config.yml create mode 100644 t/issues/gh-975/gh-975.t create mode 100644 t/issues/gh-975/test_public_dir/test.txt diff --git a/lib/Dancer2/Core/App.pm b/lib/Dancer2/Core/App.pm index 19bec8f74..225e8de91 100644 --- a/lib/Dancer2/Core/App.pm +++ b/lib/Dancer2/Core/App.pm @@ -676,7 +676,6 @@ sub _build_default_config { environment => $self->environment, appdir => $self->location, public_dir => $public, - static_handler => ( -d $public ), template => 'Tiny', route_handlers => [ [ @@ -1099,6 +1098,11 @@ sub BUILD { sub finish { my $self = shift; + + # normalize some values that require calculations + defined $self->config->{'static_handler'} + or $self->config->{'static_handler'} = -d $self->config->{'public_dir'}; + $self->register_route_handlers; $self->compile_hooks; diff --git a/t/issues/gh-975/config.yml b/t/issues/gh-975/config.yml new file mode 100644 index 000000000..727e3358d --- /dev/null +++ b/t/issues/gh-975/config.yml @@ -0,0 +1 @@ +public_dir: "t/issues/gh-975/test_public_dir" diff --git a/t/issues/gh-975/gh-975.t b/t/issues/gh-975/gh-975.t new file mode 100644 index 000000000..af0e452dd --- /dev/null +++ b/t/issues/gh-975/gh-975.t @@ -0,0 +1,15 @@ +use strict; +use warnings; +use Test::More 'tests' => 2; +use Plack::Test; +use HTTP::Request::Common; + +{ + package App; + use Dancer2; +} + +my $test = Plack::Test->create( App->to_app ); +my $res = $test->request( GET '/test.txt' ); +ok( $res->is_success, 'Succeeded retrieving file' ); +like( $res->content, qr{^this is test\.txt}, 'Correct file content' ); diff --git a/t/issues/gh-975/test_public_dir/test.txt b/t/issues/gh-975/test_public_dir/test.txt new file mode 100644 index 000000000..66e61107f --- /dev/null +++ b/t/issues/gh-975/test_public_dir/test.txt @@ -0,0 +1 @@ +this is test.txt From e4c4109b7616860a5e6b5cf030fa16c68aeb7086 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Wed, 14 Dec 2016 10:15:01 +0100 Subject: [PATCH 2/2] reflect change --- Changes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changes b/Changes index 530335fe3..0e7a844ed 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} + [ BUG FIXES ] + * GH #975: Fix "public_dir" configuration to work, just like + DANCER_PUBLIC. (Sawyer X) + [ ENHANCEMENTS ] * You can now call '$self->find_plugin(...)' within a plugin in order to find a plugin, in order to use its DSL in your