1Dancer::Config(3)     User Contributed Perl Documentation    Dancer::Config(3)
2
3
4

NAME

6       Dancer::Config - how to configure Dancer to suit your needs
7

VERSION

9       version 1.3513
10

DESCRIPTION

12       Dancer::Config handles reading and changing the configuration of your
13       Dancer apps.  The documentation for this module aims to describe how to
14       change settings, and which settings are available.
15

SETTINGS

17       You can change a setting with the keyword set, like the following:
18
19           use Dancer;
20
21           # changing default settings
22           set port         => 8080;
23           set content_type => 'text/plain';
24           set startup_info => 0;
25
26       A better way of defining settings exists: using YAML file. For this to
27       be possible, you have to install the YAML module. If a file named
28       config.yml exists in the application directory it will be loaded as a
29       setting group.
30
31       The same is done for the environment file located in the environments
32       directory.
33
34       To fetch the available configuration values use the config keyword that
35       returns a reference to a hash:
36
37           my $port   = config->{port};
38           my $appdir = config->{appdir};
39
40       By default, the module YAML will be used to parse the configuration
41       files.  If desired, it is possible to use YAML::XS instead by changing
42       the YAML engine configuration in the application code:
43
44           config->{engines}{YAML}{module} = 'YAML::XS';
45
46       See Dancer::Serializer::YAML for more details.
47

SUPPORTED SETTINGS

49   Run mode and listening interface/port
50       server (string)
51
52       The IP address that the Dancer app should bind to.  Default is 0.0.0.0,
53       i.e.  bind to all available interfaces.
54
55       Can also be set with environment variable DANCER_SERVER
56
57       port (int)
58
59       The port Dancer will listen to.
60
61       Default value is 3000. This setting can be changed on the command-line
62       with the --port switch.
63
64       Can also be set with environment variable DANCER_PORT
65
66       daemon (boolean)
67
68       If set to true, runs the standalone webserver in the background.  This
69       setting can be changed on the command-line with the --daemon flag.
70
71       Can also be enabled by setting environment variable DANCER_DAEMON to a
72       true value.
73
74       behind_proxy (boolean)
75
76       If set to true, Dancer will look to "X-Forwarded-Protocol" and
77       "X-Forwarded-host" when constructing URLs (for example, when using
78       "redirect". This is useful if your application is behind a proxy.
79
80       It will also cause Dancer::Request->address to return what
81       Dancer::Request->forwarded_for_address would return, namely the content
82       of the `HTTP_X_FORWARDED_FOR` env var/header, so that requests will
83       appear to have come from the end user's IP and not the proxy's.
84
85       Because of the above, you should *not* turn this on if your app isn't
86       behind a proxy which will pass this information on appropriately,
87       otherwise a malicious user could supply false information.
88
89   Content type / character set
90       content_type (string)
91
92       The default content type of outgoing content.  Default value is
93       'text/html'.
94
95       Can also be set with environment variable DANCER_CONTENT_TYPE
96
97       charset (string)
98
99       This setting has multiple effects:
100
101       •   It sets the default charset of outgoing content. "charset=" item
102           will be added to Content-Type response header.
103
104       •   It makes Unicode bodies in HTTP responses of "text/*" types to be
105           encoded to this charset.
106
107       •   It also indicates to Dancer in which charset the static files and
108           templates are encoded.
109
110       •   If you're using Dancer::Plugin::Database, UTF-8 support will
111           automatically be enabled for your database - see "AUTOMATIC UTF-8
112           SUPPORT" in Dancer::Plugin::Database
113
114       Default value is empty which means don't do anything. HTTP responses
115       without charset will be interpreted as ISO-8859-1 by most clients.
116
117       You can cancel any charset processing by specifying your own charset in
118       Content-Type header or by ensuring that response body leaves your
119       handler without Unicode flag set (by encoding it into some 8bit
120       charset, for example).
121
122       Also, since automatically serialized JSON responses have
123       "application/json" Content-Type, you should always encode them by hand.
124
125       Can also be set with environment variable DANCER_CHARSET
126
127       default_mime_type (string)
128
129       Dancer's Dancer::MIME module uses "application/data" as a default mime
130       type. This setting lets the user change it. For example, if you have a
131       lot of files being served in the public folder that do not have an
132       extension, and are text files, set the "default_mime_type" to
133       "text/plain".
134
135   File / directory locations
136       environment (string)
137
138       This is the name of the environment that should be used. Standard
139       Dancer applications have an "environments" folder with specific
140       configuration files for different environments (usually development and
141       production environments). They specify different kinds of error
142       reporting, deployment details, etc. These files are read after the
143       generic "config.yml" configuration file.
144
145       The running environment can be set with:
146
147          set environment => "production";
148
149       Note that this variable is also used as a default value if other values
150       are not defined.
151
152       Can also be set with environment variable DANCER_ENVIRONMENT
153
154       appdir (directory)
155
156       This is the path where your application will live.  It's where Dancer
157       will look by default for your config files, templates and static
158       content.
159
160       It is typically set by "use Dancer" to use the same directory as your
161       script.
162
163       Can also be set with environment variable DANCER_APPDIR
164
165       public (directory)
166
167       This is the directory, where static files are stored. Any existing file
168       in that directory will be served as a static file, before matching any
169       route.
170
171       By default it points to $appdir/public.
172
173       views (directory)
174
175       This is the directory where your templates and layouts live.  It's the
176       "view" part of MVC (model, view, controller).
177
178       This defaults to $appdir/views.
179
180   Templating & layouts
181       template
182
183       Allows you to configure which template engine should be used.  For
184       instance, to use Template Toolkit, add the following to "config.yml":
185
186           template: template_toolkit
187
188       layout (string)
189
190       The name of the layout to use when rendering view. Dancer will look for
191       a matching template in the directory $views/layouts.
192
193       Your can override the default layout using the third argument of the
194       "template" keyword. Check "Dancer" manpage for details.
195
196   Logging, debugging and error handling
197       strict_config (boolean, default: false)
198
199       If true, "config" will return an object instead of a hash reference.
200       See Dancer::Config::Object for more information.
201
202       global_warnings (boolean, default: false)
203
204       If true, "use warnings" will be in effect for all modules and scripts
205       loaded by your Dancer application. Default is false.
206
207       Can also be enabled by setting the environment variable DANCER_WARNINGS
208       to a true value.
209
210       startup_info (boolean)
211
212       If set to true (the default), prints a banner at server startup with
213       information such as versions and the environment (or "dancefloor").
214
215       Can also be disabled by setting the environment variable
216       DANCER_NO_STARTUP_INFO to a true value.
217
218       warnings (boolean)
219
220       If set to true, tells Dancer to consider all warnings as blocking
221       errors. Default is false.
222
223       traces (boolean)
224
225       If set to true, Dancer will display full stack traces when a warning or
226       a die occurs. (Internally sets Carp::Verbose). Default is false.
227
228       Can also be enabled by setting environment variable DANCER_TRACES to a
229       true value.
230
231       require_environment (boolean)
232
233       If set to true, Dancer will fail during startup if your environment
234       file is missing or can't be read. This is especially useful in
235       production when you have things like memcached settings that need to be
236       set per-environment.  Defaults to false.
237
238       server_tokens (boolean)
239
240       If set to true (the default), Dancer will add an "X-Powered-By" header
241       and also append the Dancer version to the "Server" header.
242
243       Can also be disabled by setting the environment variable
244       DANCER_NO_SERVER_TOKENS to a true value.
245
246       log_path (string)
247
248       Folder where the ``file "logger"'' saves log files.
249
250       log_file (string)
251
252       Name of the file to create when ``file "logger"'' is active. It
253       defaults to the "environment" setting contents.
254
255       logger (enum)
256
257       Select which logger to use.  For example, to write to log files in
258       "log_path":
259
260           logger: file
261
262       Or to direct log messages to the console from which you started your
263       Dancer app in standalone mode,
264
265           logger: console
266
267       Various other logger backends are available on CPAN, including
268       Dancer::Logger::Syslog, Dancer::Logger::Log4perl, Dancer::Logger::PSGI
269       (which can, with the aid of Plack middlewares, send log messages to a
270       browser's console window) and others.
271
272       Can also be set with environment variable DANCER_LOGGER
273
274       log (enum)
275
276       Tells which log messages should be actually logged. Possible values are
277       core, debug, warning or error.
278
279       core : all messages are logged, including some from Dancer itself
280       debug : all messages are logged
281       info : only info, warning and error messages are logged
282       warning : only warning and error messages are logged
283       error : only error messages are logged
284
285       During development, you'll probably want to use "debug" to see your own
286       debug messages, and "core" if you need to see what Dancer is doing.  In
287       production, you'll likely want "error" or "warning" only, for less-
288       chatty logs.
289
290       show_errors (boolean)
291
292       If set to true, Dancer will render a detailed debug screen whenever an
293       error is caught. If set to false, Dancer will render the default error
294       page, using $public/$error_code.html if it exists or the template
295       specified by the "error_template" setting.
296
297       The error screen attempts to sanitise sensitive looking information
298       (passwords / card numbers in the request, etc) but you still should not
299       have show_errors enabled whilst in production, as there is still a risk
300       of divulging details.
301
302       error_template (template path)
303
304       This setting lets you specify a template to be used in case of runtime
305       error. At the present moment the template can use three variables:
306
307       title
308           The error title.
309
310       message
311           The error message.
312
313       code
314           The code throwing that error.
315
316   Session engine
317       session (enum)
318
319       This setting lets you enable a session engine for your web application.
320       By default sessions are disabled in Dancer. You must choose a session
321       engine to use them.
322
323       See Dancer::Session for supported engines and their respective
324       configuration.
325
326       session_expires
327
328       The session expiry time in seconds, or as e.g. "2 hours" (see "expires"
329       in Dancer::Cookie.  By default there is no specific expiry time.
330
331       session_name
332
333       The name of the cookie to store the session ID in.  Defaults to
334       "dancer.session".  This can be overridden by certain session engines.
335
336       session_secure
337
338       The user's session ID is stored in a cookie.  If the "session_secure"
339       setting is set to a true value, the cookie will be marked as secure,
340       meaning it should only be sent over HTTPS connections.
341
342       session_is_http_only
343
344       This setting defaults to 1 and instructs the session cookie to be
345       created with the "HttpOnly" option active, meaning that JavaScript will
346       not be able to access its value.
347
348       session_domain
349
350       Allows you to set the domain property on the cookie, which will
351       override the default.  This is useful for setting the session cookie's
352       domain to something like ".domain.com" so that the same cookie will be
353       applicable and usable across subdomains of a base domain.
354
355   auto_page (boolean)
356       For simple pages where you're not doing anything dynamic, but still
357       want to use the template engine to provide headers etc, you can use the
358       auto_page feature to avoid the need to create a route for each page.
359
360       With "auto_page" enabled, if the requested path does not match any
361       specific route, Dancer will check in the views directory for a matching
362       template, and use it to satisfy the request if found.
363
364       Simply enable auto_page in your config:
365
366           auto_page: 1
367
368       Then, if you request "/foo/bar", Dancer will look in the views dir for
369       "/foo/bar.tt".
370
371       Dancer will honor your "before_template_render" code, and all default
372       variables. They will be accessible and interpolated on automaticly-
373       served pages.
374
375       The pages served this way will have "Content-Type" set to "text/html",
376       so don't use the feature for anything else.
377
378   Route caching
379       route_cache (boolean)
380
381       If true, enables route caching (for quicker route resolution on larger
382       apps - not caching of responses).  See Dancer::Route::Cache for
383       details. Default is false.
384
385       route_cache_size_limit (bytes)
386
387       Maximum size of route cache (e.g. 1024, 2M). Defaults to 10M (10MB) -
388       see Dancer::Route::Cache
389
390       route_cache_path_limit (number)
391
392       Maximum number of routes to cache. Defaults to 600 - see
393       Dancer::Route::Cache
394
395   DANCER_CONFDIR and DANCER_ENVDIR
396       It's possible to set the configuration directory and environment
397       directory using these two environment variables. Setting
398       `DANCER_CONFDIR` will have the same effect as doing
399
400           set confdir => '/path/to/confdir'
401
402       and setting `DANCER_ENVDIR` will be similar to:
403
404           set envdir => '/path/to/environments'
405

ENVIRONMENT VARIABLES

407       Some settings can be provided via environment variables at runtime, as
408       detailed above; a full list of environment variables you can use
409       follows.
410
411       DANCER_APPDIR
412
413       DANCER_APPHANDLER a Dancer::Handler::* by default
414       Dancer::Handler::Standalone
415
416       DANCER_AUTO_RELOAD
417
418       DANCER_CHARSET
419
420       DANCER_CONFDIR
421
422       DANCER_CONTENT_TYPE
423
424       DANCER_DAEMON
425
426       DANCER_ENVDIR
427
428       DANCER_ENVIRONMENT
429
430       DANCER_NO_SERVER_TOKENS
431
432       DANCER_NO_STARTUP_INFO
433
434       DANCER_LOGGER
435
436       DANCER_PORT
437
438       DANCER_SERVER
439
440       DANCER_TRACES
441
442       DANCER_WARNINGS
443

AUTHOR

445       This module has been written by Alexis Sukrieh <sukria@cpan.org> and
446       others, see the AUTHORS file that comes with this distribution for
447       details.
448

LICENSE

450       This module is free software and is released under the same terms as
451       Perl itself.
452

SEE ALSO

454       Dancer
455

AUTHOR

457       Dancer Core Developers
458
460       This software is copyright (c) 2010 by Alexis Sukrieh.
461
462       This is free software; you can redistribute it and/or modify it under
463       the same terms as the Perl 5 programming language system itself.
464
465
466
467perl v5.34.0                      2022-01-21                 Dancer::Config(3)
Impressum