Documentation

Configuration

The configuration file of your application is located in the config directory. In it you will find to files :

  • A .config file in which you can modify the application configuration.
  • A vm.args file containing optionals' arguments passed to the Erlang VM.

The vm.args file

The vm.args is similar to the standard Erlang args_file. However there is a small difference. Indeed, in this file you can use environment variables. For example, if you want to load dependencies placed in a specific directory, you can use the following line :

-pa $BASEDIR/deps/extra/*/ebin
In this example, the $BASEDIR environment variable is automaticaly set.

The .config file

The .config file is a standard Erlang configration file.

If you create an application named my_app, your configuration file will be config/my_app.config and your configuration will be in the {my_app, [...]} tuple.

List of availables options:

OptionTypeDescriptionDefault
portIntegerHTTP port8080
port_from{Atom, Atom, List}Retrieve the HTTP port to use by calling the function named by the second atom of the module (named by the first atom), using parameters specified in the list.-
ipStringBinding IP"0.0.0.0"
ip_from{Atom, Atom, List}Retrieve the binding IP by calling the function named by the second atom of the module (named by the first atom), using parameters specified in the list.-
max_connIntegerMaximum number of connections.100
max_conn_from{Atom, Atom, List}Retrieve the maximum number of connections by calling the function named by the second atom of the module (named by the first atom), using parameters specified in the list.-
ssl[Tuple]SSL configuration (see below).[]
routes[Tuple]Custom routes (see below).[]
plugins[Atom]Third party plugins to use (see the plugin section of this documentation).[]
start[Tuple]List of applications and modules to start just after the start of the HTTP server (see below).[]
mail[Tuple]SMTP configuration (see below).[{relay, "localhost"}, {port, 25}]

Custom routes

If you want to use a custom route for a controller, you can specify it in the routes section of the configuration file. Thus, if you want to access the my_controller controller via /my/custom/path, just add the following tuple in the list of the routes' option :

{"/my/custom/path", my_controller}

You can add as many route as you want. You can also specify multiple routes for a controller :

[
  {my_app, [
    ...
    {routes, [
      {"/first/route", my_controller},
      {"/second/route", my_controller}
    ]},
    ...
  ]},
  ...
]

You can also create "redirection route" :

[
  {my_app, [
    ...
    {routes, [
      {"/my/redirect", {redirect, "/my/destination", [{"q", "value"}]}
    ]},
    ...
  ]},
  ...
]

In this example, accessing /my/redirect will redirect you to /my/destination?q=value. In the same way, /my/redirect?q=custon&l=FR will redirect you to /my/destination?q=value&l=FR.

Be aware that if you specify a same route for two different controllers, only the second one will be accessible via the given route.

Using HTTPS

To use HTTPS (instead of HTTP), you just need to specify a SLL configuration. This is done by giving the names of the certificates files and key file in the SSL section of the configuration file. In this section you can specify :

  • cacertfile PEM encoded trusted certificates file used to verify peer certificates.
  • certfile PEM encoded user certificate file. May also contain the private key.
  • keyfile PEM encoded private key file, if different than the certfile.
Each value of these options is a simple file name as string (ex: server.crt). In addition, each file must be placed in the ssl directory of the priv directory of the application.

SMTP configuration

If you want to use a mailer you must specify the SMTP configuration. In this section you can use the following options :

  • relay: SMTP server address.
  • port: SMTP port.
  • ssl: true if you use SMTPS, false otherwise.
  • username: Username if SMTP authentification is needed.
  • password: Password if SMTP authentification is needed.

Start applications and modules

The start section of the configuration file allow you to specify applications or modules that must be started automatically after the launch of the HTTP server.

To start and application, create a tuple {application, ApplicationName}, where ApplicationName is the name of the application. In this case, the application will be started using application:start/1. If you want to start the application using application:ensure_all_started/1, add ensure as third element in the tuple.

To start a module, create a tuple {module, ModuleName, Args}, where ModuleName is the name of the module and Args is the list of parameters to pass to the start function of the module.