[Dancer-users] multiple apps via a single app.psgi vs. many isolated single apps
Perlover
perlover at perlover.com
Wed Nov 23 17:23:10 CET 2011
Good day!
I have a following Dancer + Starman bundle where i have many sites
under one module software (MyModule for example)
Example of my .psgi file
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
BEGIN {
use Dancer 1.3080 ':syntax';
setting apphandler => 'PSGI';
# Loading configs from one location
Dancer::Config::setting(appdir => "$ENV{MYAPP_ROOTDIR}/etc/dancer/sites");
Dancer::Config::setting(confdir => "$ENV{MYAPP_ROOTDIR}/etc/dancer/sites");
Dancer::Config->load;
# Loading configs from other location
Dancer::Config::setting(appdir => "$ENV{MYAPP_ROOTDIR}/etc/dancer");
Dancer::Config::setting(confdir => "$ENV{MYAPP_ROOTDIR}/etc/dancer");
Dancer::Config->load;
}
use MyModule;
use Plack::Builder;
my $conf = config->{my_own_settings};
builder {
enable sub {
my $app = shift;
sub {
my $env = shift;
$env->{HTTP_HOST} =~ s/:\d+$//o; # If port of fronend differents from backend
return $app->($env);
};
};
builder {
my $last;
foreach my $host ( keys %{$conf->{sites}} ) {
$last = mount $host => builder {
enable "Runtime";
sub {
my $env = shift;
local $ENV{DANCER_APPDIR} = "$conf->{sites}{$host}{appdir}";
load_app "MyModule";
Dancer::App->set_running_app('MyModule');
setting appdir => $ENV{DANCER_APPDIR};
Dancer::Config->load;
my $request = Dancer::Request->new( env => $env );
Dancer->dance($request);
};
}
}
$last;
};
};
And my config of my sites (other config.yml - not main config.yml!) -
$ENV{MYAPP_ROOTDIR}/etc/dancer/sites/config.yml
my_own_settings:
sites:
http://app1.home.com/:
appdir: $$MYAPP_ROOTDIR$$/sites/site1
database: 'db1'
http://app2.home.com/:
appdir: $$MYAPP_ROOTDIR$$/sites/site2
database: 'db1'
I hope it will help to you
Perlover
2011/11/23 Puneet Kishor <punk.kish at gmail.com>:
> Inspired by the conversation about deploying multiple apps, and the problems with current Dancer version to dispatch the routes correctly, I have a slightly meta question: What exactly is the advantage of launching multiple apps via a single app.psgi file? Here is my motivation --
>
> I have a multitude of different Dancer apps running on my computer (see http://earth-base.org/apps). The issue I face is that they are all in separate directories, and have different layout files even though they are all identical in appearance and most of their functionality. Just like Dancer.pm itself is installed in one location, and any upgrades to it are available to all my apps, I would also like to abstract the views and css and js. For example, I use the html5 boilerplate from http://html5boilerplate.com/ for all my apps. This means if I want to install the latest build of html5 boilerplate, I have to update it for all my apps. How could I make some of the currently app-specific views to be served from a single location? Would the multiple-apps-via-a-single-app.psgi help here?
>
> --
> Puneet Kishor
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
>
More information about the Dancer-users
mailing list