Permalink
Browse files

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.
  • Loading branch information...
1 parent a171120 commit f2ac574e750616b80f54ce3de7523a9d87b259b3 @xsawyerx xsawyerx committed with cromedome Dec 14, 2016
Showing with 22 additions and 1 deletion.
  1. +5 −1 lib/Dancer2/Core/App.pm
  2. +1 −0 t/issues/gh-975/config.yml
  3. +15 −0 t/issues/gh-975/gh-975.t
  4. +1 −0 t/issues/gh-975/test_public_dir/test.txt
@@ -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;
@@ -0,0 +1 @@
+public_dir: "t/issues/gh-975/test_public_dir"
@@ -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' );
@@ -0,0 +1 @@
+this is test.txt

0 comments on commit f2ac574

Please sign in to comment.