Dancer + Plack/Starman - location of .psgi matters?
It seems to matter whether my .psgi is in MyApp/bin or MyApp/other This works: starman -E development -a bin/app.development.psgi ... This doesn't (complains about config not being loaded): starman -E development -a res/app.development.psgi ... Makes no difference if I give a full path or not. I get the same error with "plackup" rather than "starman" too. Current versions of Dancer/Starmam. I'm guessing it's something to do with Dancer figuring out paths, but can't quite figure out what. TIA --- app.development.psgi file --- use Dancer; use Plack; load_app 'MyApp'; use Dancer::Config 'setting'; setting apphandler => 'PSGI'; Dancer::Config->load; my $app1 = sub { my $env = shift; my $request = Dancer::Request->new( $env ); Dancer->dance( $request ); }; -- Richard Huxton Archonet Ltd
That's odd. Could you please open a corresponding ticket in Github Issues? Much appreciated! Thanks, Sawyer. On Fri, May 6, 2011 at 7:54 PM, Richard Huxton <dev@archonet.com> wrote:
It seems to matter whether my .psgi is in MyApp/bin or MyApp/other
This works: starman -E development -a bin/app.development.psgi ... This doesn't (complains about config not being loaded): starman -E development -a res/app.development.psgi ...
Makes no difference if I give a full path or not. I get the same error with "plackup" rather than "starman" too. Current versions of Dancer/Starmam.
I'm guessing it's something to do with Dancer figuring out paths, but can't quite figure out what.
TIA
--- app.development.psgi file --- use Dancer; use Plack; load_app 'MyApp';
use Dancer::Config 'setting'; setting apphandler => 'PSGI'; Dancer::Config->load;
my $app1 = sub { my $env = shift; my $request = Dancer::Request->new( $env ); Dancer->dance( $request ); };
-- Richard Huxton Archonet Ltd _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
2011/5/7 Richard Huxton <dev@archonet.com>:
This works: starman -E development -a bin/app.development.psgi ... This doesn't (complains about config not being loaded): starman -E development -a res/app.development.psgi ...
Dancer.pm have a below code in sub _init_script_dir. ------------------------------------------------------------------------- # in bin/ or public/ we need to go one level upper to find the appdir $LAYOUT_PRE_DANCER_1_2 = 0 if ($script_dirs[$#script_dirs - 1] eq 'bin') or ($script_dirs[$#script_dirs - 1] eq 'public'); my $appdir = $ENV{DANCER_APPDIR} || ( $LAYOUT_PRE_DANCER_1_2 ? $script_path : File::Spec->rel2abs(Dancer::path($script_path, '..')) ); Dancer::setting(appdir => $appdir); ------------------------------------------------------------------------- So, bin and public dir are special case which appdir is set to one level upper path. You may work around the problem to set DANCER_APPDIR environment variable. for example DANCER_APPDIR=`pwd` starman -E development -a res/app.development.psgi ... -- Takeshi OKURA
On 09/05/11 12:24, Takeshi OKURA wrote:
2011/5/7 Richard Huxton<dev@archonet.com>:
This works: starman -E development -a bin/app.development.psgi ... This doesn't (complains about config not being loaded): starman -E development -a res/app.development.psgi ...
Dancer.pm have a below code in sub _init_script_dir. [snip] So, bin and public dir are special case which appdir is set to one level upper path.
Aha - I thought something like that must be happening. Thanks very much for this pointer.
You may work around the problem to set DANCER_APPDIR environment variable. for example DANCER_APPDIR=`pwd` starman -E development -a res/app.development.psgi ...
Hmm - looks like a documentation patch might be useful, since I don't remember seeing DANCER_APPDIR mentioned anywhere. Hmm - it's not possible to set this simply in the .psgi because it's needed at "use" time. So - this doesn't work: $ENV{DANCER_APPDIR} = "/srv/Projects/oldford_db/src/tmp/test1"; use Dancer; ...rest of script... But this does: BEGIN { $ENV{DANCER_APPDIR} = "/srv/Projects/oldford_db/src/tmp/test1"; } use Dancer; ...rest of script... Would there be any interest in some elements of the following? 1. Have an explicit appdir (syntax just a suggestion) use Dancer appdir=>'/path/to/myapp' 2. If that isn't provided, check ENV as at present 3. If that isn't provided, try based on script dir Be a bit stricter than at present, perhaps check for: bin/ && public/ && config.yml 4. If that fails, die and explain why. I think steps #3,4 are valuable in themselves. If my app had just died and told me to check the docs re: appdir then that would have saved me any pain. -- Richard Huxton Archonet Ltd
participants (3)
-
Richard Huxton -
sawyer x -
Takeshi OKURA