I've been developing my first Mojolicious application. Til now I've been running it from the development directory, but now I want to install on the production servers. mojo generate app
produced the directories templates/ and public/ which I have been using to store templates and static files. I created a simple distribution with Dist::Zilla, but I couldn't get at templates/ and public/ during runtime.
The solution I've come with is to move templates/ and public/ into a new directory share/, and let File::ShareDir (or Dist::Zilla's ShareDir plugin) pick it up so that I can configure the appropriate paths in my *_mode methods:
sub development_mode{
my $app = shift;
push @{$app->static->paths}, rel2abs(catdir('share', 'public') );
push @{$app->renderer->paths}, rel2abs(catdir('share', 'templates') );
}
sub production_mode{
my $app = shift;
push @{$app->static->paths}, catdir(dist_dir('FooBar'), 'public') ;
push @{$app->renderer->paths}, catdir(dist_dir('FooBar'), 'templates') ;
}
Is there a more official way to do this?
Nope, that's how I do it, both for Galileo and my more generic plugin which does this for you: Mojolicious::Plugin::InstallablePaths.