The main configurations of the project are located in the `./config` directory. Additional configs can be added in the `./api/**/config` folder of each API and plugin by creating JavaScript or JSON files.
## Application
Contains the main configurations relative to your project.
**Path —** `./config/application.json`.
```json
{
"favicon": {
"path": "favicon.ico",
"maxAge": 86400000
},
"public": {
"path": "./public",
"maxAge": 60000
}
}
```
-`favicon`
-`path` (string): Path to the favicon file. Default value: `favicon.ico`.
-`maxAge` (integer): Cache-control max-age directive in ms. Default value: `86400000`.
-`public`
-`path` (string): Path to the public folder. Default value: `./public`.
-`maxAge` (integer): Cache-control max-age directive in ms. Default value: `60000`.
***
## Custom
Add custom configurations to the project. The content of this file is available through the `strapi.config` object.
#### Example
**Path —** `./config/custom.json`.
```json
{
"backendURL": "http://www.strapi.io",
"mainColor": "blue"
}
```
These configurations are accessible through `strapi.config.backendURL` and `strapi.config.mainColor`.
***
## Language
As described in the [i18n documentation](../plugin-development/frontend-development.md#i18n), Strapi includes an internationalization system. This is especially useful to translate API messages (errors, etc.).
**Path —** `./config/language.json`.
```json
{
"enabled": true,
"defaultLocale": "en_us",
"modes": [
"query",
"subdomain",
"cookie",
"header",
"url",
"tld"
],
"cookieName": "locale"
}
```
-`enabled` (boolean): Enable or disable i18n. Default value: `true`.
-`defaultLocale` (string): Default locale used by the application. Default value: `en_us`.
-`modes` (array): Methods used to detect client language. Default value: `["query", "subdomain", "cookie", "header", "url", "tld"]`.
-`cookieName` (string): Name of the cookie used to store the locale name. Default value: `locale`.
***
## Functions
The `./config/functions/` folder contains a set of JavaScript files in order to add dynamic and logic based configurations.
### Bootstrap
**Path —** `./config/functions/bootstrap.js`.
The `bootstrap` function is called at every server start. You can use it to add a specific logic at this moment of your server's lifecycle.
Here are some use cases:
- Create an admin user if there isn't.
- Fill the database with some necessary data.
- Check that the database is up-and-running.
### CRON tasks
CRON tasks allow you to schedule jobs (arbitrary functions) for execution at specific dates, with optional recurrence rules. It only uses a single timer at any given time (rather than reevaluating upcoming jobs every second/minute).
::: note
Make sure the `enabled` cron config is set to `true` in your environment's variables.
:::
The cron format consists of:
```
** ** * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
```
To define a CRON job, add your logic like bellow:
**Path —** `./config/functions/cron.js`.
```js
module.exports = {
/**
* Simple example.
* Every monday at 1am.
*/
'0 0 1 * * 1': () => {
// Add your own logic here (eg. send a queue of email, create a database backup, etc.).
}
};
```
### Bookshelf, Mongoose
**Path —** `./config/functions/bookshelf.js`.
**Path —** `./config/functions/mongoose.js`.
When present, they are loaded to let you customize your database connection instance, for example for adding some plugin, customizing parameters, etc.
As an example, for using the `mongoose-simple-random` plugin for MongoDB, you can register it like this:
**Path —** `./config/functions/mongoose.js`.
```js
'use strict';
const random = require('mongoose-simple-random');
module.exports = (mongoose, connection) => {
mongoose.plugin(random);
};
```
***
## Locales
The `locales` directory contains the translations of your API.
Each JSON file located in the folder must have the name of its corresponding translation (eg. `en_US.json`, `fr_FR.json`, etc.). Each line defines a translation key and its corresponding value.
#### Example
**Path —** `./config/locales/en_US.json`.
```js
{
"welcome": "Welcome"
}
```
> Take a look at the [internationalization's guide](../guides/i18n.md) for more details.
***
## Environments
Most of the application's configurations are defined by environment. It means that you can specify settings for each environment (`development`, `production`, `test`, etc.).
::: note
You can access the config of the current environment through `strapi.config.currentEnvironment`.
-`debug` (boolean): Show database exchanges and errors.
-`autoMigration` (boolean): To disable auto tables/columns creation for SQL database.
-`pool` Options used for database connection pooling. For more information look at [Knex's pool config documentation](https://knexjs.org/#Installation-pooling).
-`min` (integer): Minimum number of connections to keep in the pool. Default value: `0`.
-`max` (integer): Maximum number of connections to keep in the pool. Default value: `10`.
-`acquireTimeoutMillis` (integer): Maximum time in milliseconds to wait for acquiring a connection from the pool. Default value: `2000` (2 seconds).
-`createTimeoutMillis` (integer): Maximum time in milliseconds to wait for creating a connection to be added to the pool. Default value: `2000` (2 seconds).
-`idleTimeoutMillis` (integer): Number of milliseconds to wait before destroying idle connections. Default value: `30000` (30 seconds).
-`reapIntervalMillis` (integer): How often to check for idle connections in milliseconds. Default value: `1000` (1 second).
-`createRetryIntervalMillis` (integer): How long to idle after a failed create before trying again in milliseconds. Default value: `200`.
-`expose` (array): Configures the `Access-Control-Expose-Headers` CORS header. If not specified, no custom headers are exposed. Default value: `["WWW-Authenticate", "Server-Authorization"]`.
-`maxAge` (integer): Configures the `Access-Control-Max-Age` CORS header. Default value: `31536000`.
-`credentials` (boolean): Configures the `Access-Control-Allow-Credentials` CORS header. Default value: `true`.
-`methods` (array)|String - Configures the `Access-Control-Allow-Methods` CORS header. Default value: `["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]`.
-`headers` (array): Configures the `Access-Control-Allow-Headers` CORS header. If not specified, defaults to reflecting the headers specified in the request's Access-Control-Request-Headers header. Default value: `["Content-Type", "Authorization", "X-Frame-Options"]`.
-`ip`
-`enabled` (boolean): Enable or disable IP blocker. Default value: `false`.
As an example using this configuration with Nginx your server would respond to `https://example.com:8443` instead of `http://localhost:1337`
**Note:** you will need to configure Nginx or Apache as a proxy before configuring this example.
```json
{
"host": "localhost",
"port": 1337,
"proxy": {
"enabled": true,
"ssl": true,
"host": "example.com",
"port": 8443
},
"cron": {
"enabled": true
}
}
```
***
## Dynamic configurations
For security reasons, sometimes it's better to set variables through the server environment. It's also useful to push dynamics values into configurations files. To enable this feature into JSON files, Strapi embraces a JSON-file interpreter into his core to allow dynamic value in the JSON configurations files.
### Syntax
The syntax is inspired by the [template literals ES2015 specifications](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). These dynamic values are indicated by the Dollar sign and curly braces (`${expression}`).
#### Usage
In any JSON configurations files in your project, you can inject dynamic values like this:
You can't execute functions inside the curly braces. Only strings are allowed.
:::
***
## Database configuration
Configuration files are not multi server friendly. So we create a data store for config you will want to update in production.
#### Usage
## Get settings:
-`environment` (string): Sets the environment you want to store the data in. By default it's current environment (can be an empty string if your config is environment agnostic).
-`type` (string): Sets if your config is for an `api`, `plugin` or `core`. By default it's `core`.
-`name` (string): You have to set the plugin or api name if `type` is `api` or `plugin`.
-`key` (string, required): The name of the key you want to store.
```js
// strapi.store(object).get(object);
// create reusable plugin store variable
const pluginStore = strapi.store({
environment: strapi.config.environment,
type: 'plugin',
name: 'users-permissions'
});
await pluginStore.get({key: 'grant'});
```
## Set settings:
-`value` (any, required): The value you want to store.