diff --git a/lib/Dancer2/Core/App.pm b/lib/Dancer2/Core/App.pm index d88096bd6..d7164232f 100644 --- a/lib/Dancer2/Core/App.pm +++ b/lib/Dancer2/Core/App.pm @@ -727,6 +727,9 @@ sub BUILD { my $self = shift; $self->init_route_handlers(); $self->_init_hooks(); + + #Siteroot is saved as fallback when no config file is found using App's path + Dancer2->runner->set_siteroot($self->location) if($self->name && $self->name eq 'main'); } sub finish { diff --git a/lib/Dancer2/Core/Role/ConfigReader.pm b/lib/Dancer2/Core/Role/ConfigReader.pm index 8392aa847..67a4653b8 100644 --- a/lib/Dancer2/Core/Role/ConfigReader.pm +++ b/lib/Dancer2/Core/Role/ConfigReader.pm @@ -104,9 +104,9 @@ sub _build_default_config { +{} } sub _build_environment { 'development' } sub _build_config_files { - my ($self) = @_; + my ($self, $forced_location) = @_; - my $location = $self->config_location; + my $location = $forced_location || $self->config_location; # an undef location means no config files for the caller return [] unless defined $location; @@ -124,8 +124,23 @@ sub _build_config_files { push @files, $path; } } - - return [ sort @files ]; + if(@files) + { + return [ sort @files ]; + } + else + { + #If no file is found in the app config path, search will be repeated under the siteroot. + #This fallback will not be activated if a forced_location is provided (to avoid loop) + if(! $forced_location && Dancer2->runner->config->{'siteroot'}) + { + return $self->_build_config_files(Dancer2->runner->config->{'siteroot'}); + } + else + { + return [ sort @files ]; #Dumb answer, @files is still empty + } + } } sub _build_config { diff --git a/lib/Dancer2/Core/Runner.pm b/lib/Dancer2/Core/Runner.pm index 9100be0c0..2b5cb187c 100644 --- a/lib/Dancer2/Core/Runner.pm +++ b/lib/Dancer2/Core/Runner.pm @@ -106,6 +106,12 @@ sub _build_config { }; } +sub set_siteroot { + my $self = shift; + my $siteroot = shift; + $self->config->{'siteroot'} = $siteroot; +} + sub BUILD { my $self = shift;