On Wed, Dec 15, 2010 at 4:11 AM, Joel Roth <joelz@pobox.com> wrote:
On Wed, Dec 15, 2010 at 12:44:14AM +0200, Gabor Szabo wrote:
in the $appdir/environments subdir there are two yml files for configuration in development and production environment.
How do I configure which environment is the application running in?
I tried to find it in http://search.cpan.org/dist/Dancer/lib/Dancer/Config.pm but could not find it.
Hi Gabor,
You could pass it as a command-line argument.
$ myapp.pl --environment=production
I think that the rationale is that you don't have to keep the same configuration file with two different sets of values in the different environments, not even for a single configuration line to tell whether it's a development or a production environment, so leaving the option to the command-line invocation is a sane choice because it defers the decision up to the very last moment and this is not written anywhere (supposing you know in which environment you are!).
But I put it right in the script:
BEGIN { push @ARGV, qw(--environment=production) }
This solution seems to require a modification of the script when you deploy the application, which might introduce a potential for error if you forget this post-deploy activity. Of course it depends on your deploy strategy - e.g. do you redeploy the script all the times? - and on many other factors - e.g. do I control both the development and the production environments? I'd push the laziness a bit more and keep two scripts (development.pl and production.pl) in the bin directory each with the trick above, in order to avoid the need to do any kind of post-deploy activities. At this point it's only a matter of calling the right script. Keeping two shell wrappers might be another option (even though I'd avoid it in a CGI deploy). Just my 2c, Flavio.