Dancer::Config - how to configure Dancer to suit your needs
Dancer::Config handles reading and changing the configuration of your Dancer apps. The documentation for this module aims to describe how to change settings, and which settings are available.
You can change a setting with the keyword set, like the following:
use Dancer; # changing default settings set port => 8080; set content_type => 'text/plain'; set startup_info => 0;
A better way of defining settings exists: using YAML file. For this to be possible, you have to install the YAML module. If a file named config.yml exists in the application directory, it will be loaded, as a setting group.
The same is done for the environment file located in the environments directory.
The IP address that the Dancer app should bind to. Default is 0.0.0.0, i.e. bind to all available interfaces.
The port Dancer will listen to.
Default value is 3000. This setting can be changed on the command-line with the --port switch.
If set to true, runs the standalone webserver in the background. This setting can be changed on the command-line with the --daemon flag.
If set to true, Dancer will look to
X-Forwarded-host when constructing URLs (for example, when using
redirect. This is useful if your application is behind a proxy.
The default content type of outgoing content. Default value is 'text/html'.
This setting has multiple effects:
charset=item will be added to Content-Type response header.
text/*types to be encoded to this charset.
Default value is empty which means don't do anything. HTTP responses without charset will be interpreted as ISO-8859-1 by most clients.
You can cancel any charset processing by specifying your own charset in Content-Type header or by ensuring that response body leaves your handler without Unicode flag set (by encoding it into some 8bit charset, for example).
Also, since automatically serialized JSON responses have
application/json Content-Type, you should always encode them by hand.
Dancer's Dancer::MIME module uses
application/data as a default mime type. This setting lets the user change it. For example, if you have a lot of files being served in the public folder that do not have an extension, and are text files, set the
This is the name of the environment that should be used. Standard Dancer applications have a
environments folder with specific configuration files for different environments (usually development and production environments). They specify different kind of error reporting, deployment details, etc. These files are read after the generic
config.yml configuration file.
The running environment can be set with:
set environment => "production";
Note that this variable is also used as a default value if other values are not defined.
This is the path where your application will live. It's where Dancer will look by default for your config files, templates and static content.
It is typically set by
use Dancer to use the same directory as your script.
This is the directory, where static files are stored. Any existing file in that directory will be served as a static file, before matching any route.
By default, it points to $appdir/public.
This is the directory where your templates and layouts live. It's the "view" part of MVC (model, view, controller).
This defaults to $appdir/views.
Allows you to configure which template engine should be used. For instance, to use Template Toolkit, add the following to
The name of the layout to use when rendering view. Dancer will look for a matching template in the directory $views/layout.
Your can override the default layout using the third argument of the
template keyword. Check
Dancer manpage for details.
config will return an object instead of a hash reference. See Dancer::Config::Object for more information.
use warnings will be in effect for all modules and scripts loaded by your Dancer application. Default is false.
If set to true (the default), prints a banner at server startup with information such as versions and the environment (or "dancefloor"). Default is true.
Conforms to the environment variable DANCER_STARTUP_INFO.
If set to true, tells Dancer to consider all warnings as blocking errors. Default is false.
If set to true, Dancer will display full stack traces when a warning or a die occurs. (Internally sets Carp::Verbose). Default is false.
If set to true, Dancer will fail during startup if your environment file is missing or can't be read. This is especially useful in production when you have things like memcached settings that need to be set per-environment. Default to false.
If set to true (the default), Dancer will add an "X-Powered-By" header and also append the Dancer version to the "Server" header.
You can also use the environment variable
Folder where the ``file
logger'' saves logfiles.
Name of the file to create when ``file
logger'' is active. It defaults to the
environment setting contents.
Select which logger to use. For example, to write to log files in
Or to direct log messages to the console from which you started your Dancer app in standalone mode,
Various other logger backends are available on CPAN, including Dancer::Logger::Syslog, Dancer::Logger::Log4perl, Dancer::Logger::PSGI (which can, with the aid of Plack middlewares, send log messages to a browser's console window) and others.
Tells which log messages should be actually logged. Possible values are core, debug, warning or error.
During development, you'll probably want to use
debug to see your own debug messages, and
core if you need to see what Dancer is doing. In production, you'll likely want
warning only, for less-chatty logs.
If set to true, Dancer will render a detailed debug screen whenever an error is caught. If set to false, Dancer will render the default error page, using $public/$error_code.html if it exists or the template specified by the
The error screen attempts to sanitise sensitive looking information (passwords / card numbers in the request, etc) but you still should not have show_errors enabled whilst in production, as there is still a risk of divulging details.
This setting lets you specify a template to be used in case of runtime error. At the present moment the template can use three variables:
If set to true, Dancer will reload the route handlers whenever the file where they are defined is changed. This is very useful in development environment but should not be enabled in production. Enabling this flag in production yields a major negative effect on performance because of Module::Refresh.
When this flag is set, you don't have to restart your webserver whenever you make a change in a route handler.
Note that Module::Refresh only operates on files in
%INC, so if the script your Dancer app is started from changes, even with auto_reload enabled, you will still not see the changes reflected until you start your app.
This setting lets you enable a session engine for your web application. Be default, sessions are disabled in Dancer, you must choose a session engine to use them.
See Dancer::Session for supported engines and their respective configuration.
The session expiry time in seconds, or as e.g. "2 hours" (see "expires" in Dancer::Cookie. By default, there is no specific expiry time.
The name of the cookie to store the session ID in. Defaults to
dancer.session. This can be overridden by certain session engines.
The user's session ID is stored in a cookie. If the
session_secure setting is set to a true value, the cookie will be marked as secure, meaning it should only be sent over HTTPS connections.
This setting defaults to 1 and instructs the session cookie to be created with the
Allows you to set the domain property on the cookie, which will override the default. This is useful for setting the session cookie's domain to something like
.domain.com so that the same cookie will be applicable and usable across subdomains of a base domain.
For simple pages where you're not doing anything dynamic, but still want to use the template engine to provide headers etc, you can use the auto_page feature to avoid the need to create a route for each page.
auto_page enabled, if the requested path does not match any specific route, Dancer will check in the views directory for a matching template, and use it to satisfy the request if found.
Simply enable auto_page in your config:
Then, if you request
/foo/bar, Dancer will look in the views dir for
Dancer will honor your
before_template_render code, and all default variables. They will be accessible and interpolated on automatic served pages.
The pages served this way will have
Content-Type set to
text/html, so don't use the feature for anything else.
If true, enables route caching (for quicker route resolution on larger apps - not caching of responses). See Dancer::Route::Cache for details. Default is false.
Maximum size of route cache (e.g. 1024, 2M). Defaults to 10M (10MB) - see Dancer::Route::Cache
Maximum number of routes to cache. Defaults to 600 - see Dancer::Route::Cache
It's possible to set the configuration directory and environment directory using this two environment variables. Setting `DANCER_CONFDIR` will have the same effect as doing
set confdir => '/path/to/confdir'
and setting `DANCER_ENVDIR` will be similar to:
set envdir => '/path/to/environments'
This module has been written by Alexis Sukrieh <email@example.com> and others, see the AUTHORS file that comes with this distribution for details.
This module is free software and is released under the same terms as Perl itself.